Giter Site home page Giter Site logo

Comments (7)

iluuu1994 avatar iluuu1994 commented on August 25, 2024 1

var_export() doesn't really support references to begin with. E.g:

$a = ['foo'];
$b = [&$a, &$a];
var_export($b);

Results in:

array (
  0 => 
  array (
    0 => 'foo',
  ),
  1 => 
  array (
    0 => 'foo',
  ),
)

Honestly, I'm not sure supporting recursive arrays is a worthwhile goal. Recursive arrays are a foot gun, because many things can trigger fatal errors. E.g.:

$a = [&$a];
var_dump($a === [[]]);

Can you clarify what your use-case is?

from php-src.

iluuu1994 avatar iluuu1994 commented on August 25, 2024 1

@carlosmintfan Thank you for clarifying! In that case, I'd honestly prefer closing this as a #wontfix until we know why we're doing it. But I'll keep this open for a few days for others to chime in.

from php-src.

carlosmintfan avatar carlosmintfan commented on August 25, 2024

I don't really have a practical use case for it. This was just an idea how it could be implemented theoretically. :)

from php-src.

carlosmintfan avatar carlosmintfan commented on August 25, 2024
$a = [&$a];
var_dump($a === [[]]);

Oh wow, why doesn't this just eval to false?

from php-src.

iluuu1994 avatar iluuu1994 commented on August 25, 2024

In this case, we probably could. But encountering recursive elements doesn't necessarily mean the elements are not equal. For example:

$a = [&$a];
$b = [[&$b]];
$a === $b;

These arrays should be equal, but understanding they are equal can get quite tricky. While we could probably find a solution for this but it might impact performance of comparison overall, which would not be a good trade-off IMO. I'm not exactly sure why we're not just throwing an Error, instead of a fatal error. I'll have a look at that.

from php-src.

carlosmintfan avatar carlosmintfan commented on August 25, 2024

In this case, we probably could. But encountering recursive elements doesn't necessarily mean the elements are not equal. For example:

$a = [&$a];

$b = [[&$b]];

$a === $b;

These arrays should be equal, but understanding they are equal can get quite tricky. While we could probably find a solution for this but it might impact performance of comparison overall, which would not be a good trade-off IMO. I'm not exactly sure why we're not just throwing an Error, instead of a fatal error. I'll have a look at that.

LOL, yeah $var = [&$var] is theoretically the same as $var = [[&$var]] cause Infinity + 1 stays Infinity, but I guess var_dumping them, the output will be different. I'll try it later today.

from php-src.

carlosmintfan avatar carlosmintfan commented on August 25, 2024

So yeah,

php > $a = [&$a];
php > $b = [[&$b]];
php > var_dump($a);
array(1) {
  [0]=>
  *RECURSION*
}
php > var_dump($b);
array(1) {
  [0]=>
  array(1) {
    [0]=>
    *RECURSION*
  }
}
php >

Hmm, yeah, but it's all theory for me, I don't use this anyway, at least until now. ๐Ÿ˜„

from php-src.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.