php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50739 === could be a bit smarter with arrays...
Submitted: 2010-01-13 12:49 UTC Modified: 2010-01-13 13:01 UTC
From: zhalassy at loginet dot hu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.12 OS: Irrelevant
Private report: No CVE-ID: None
 [2010-01-13 12:49 UTC] zhalassy at loginet dot hu
Description:
------------
At the moment, you can't do things like:

$GLOBALS === $GLOBALS;

or

$a = array('a' => &$a); $a === $a['a'];

both causes fatal error claiming too deep nesting level.

I find it rather strange that you can use references, but you can't test if something is referencing the same thing or not...

It would be nice to have some ==== or is_same(&$a,&$b) function which would just do a lookup in the symbol table and if the two variables referencing the same thing it would return true, false otherwise.


Reproduce code:
---------------
$a = is_same($GLOBALS,$GLOBALS);

$x = array('x' => &$x);
$b = is_same($x, $x['x']);

$x1 = array('c' => &$x1);
$x2 = array('c' => &$x2); //same layout, but not the same variable;
$c = is_same($x1,$x2);

$y1 = "test";
$y2 = $y1; /* plain assignement, maybe same till y1 or y2 not changed, but is_same() shouldn't get affected by optimization behaviour */
$d = is_same($y1,$y2);

$z1 = "test2";
$z2 = &$z1; //or $z2 =& $z1;
$e = is_same($z1,$z2);

Expected result:
----------------
$a === true;
$b === true;
$c === false;
$d === false;
$e === true;



Actual result:
--------------
No way to do this ATM (AFAIK). But please tell me if i didn't read the documentation properly...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-13 13:01 UTC] jani@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC