Edit report at http://bugs.php.net/bug.php?id=52907&edit=1
ID: 52907
User updated by: a_different_name at hotmail dot com
Reported by: a_different_name at hotmail dot com
Summary: "is" operator -- test whether two lvalues are
references to each other
Status: Open
Type: Feature/Change Request
Package: Variables related
PHP Version: Irrelevant
Block user comment: N
New Comment:
The second line of the test script would actually be better as
$b = $a;
as it would test whether ($a is $b) is broken if you simply assign one
variable to
another. (It should be false if changing $a won't also change $b, but
my
understanding is that PHP does some copy-on-write thing when assigning
-- meaning
that $a and $b could *appear* identical even though they're not.)
Previous Comments:
------------------------------------------------------------------------
[2010-09-22 17:18:36] a_different_name at hotmail dot com
Description:
------------
Currently, PHP has "==", which loosely checks for equality, and "===",
which
strictly checks for equality. However, for strings and booleans and
such, both
only test for equality -- there's no way to know (without altering the
variable's
contents) whether two variables are identical references unless they
refer to an
object.
If PHP allows the creation of references, there should be some safe and
built-in
way of testing whether that's been done, so values don't get
unexpectedly mangled.
Test script:
---------------
$a = 'test';
$b = "$a"; // Interpolated, so it should not be pooled or anything if
PHP does that
$c =& $a;
// These all print
if ($a == $b) print "\$a == \$b\n";
if ($b == $c) print "\$b == \$c\n";
if ($a == $c) print "\$a == \$c\n";
// These all print too, as expected
if ($a === $b) print "\$a === \$b\n";
if ($b === $c) print "\$b === \$c\n";
if ($a === $c) print "\$a === \$c\n";
// I use "is" here, because other languages use it
// if they don't already use /==+/ for this purpose.
if ($a is $b) print "\$a is \$b\n"; // should not print
if ($b is $c) print "\$b is \$c\n"; // should not print
if ($a is $c) print "\$a is \$c\n"; // should run
Expected result:
----------------
$a == $b
$b == $c
$a == $c
$a === $b
$b === $c
$a === $c
$a is $c
Actual result:
--------------
Parse error. (There is no "is" operator yet, and no reasonable
replacement.)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52907&edit=1