Req #52907 [Opn->Dup]: "is" operator -- test whether two lvalues are references to each other

From: Date: Sat, 26 Mar 2016 23:57:29 +0000
Subject: Req #52907 [Opn->Dup]: "is" operator -- test whether two lvalues are references to each other
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200138@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52907&edit=1 ID: 52907 Updated by: nikic@php.net Reported by: a_different_name at hotmail dot com Summary: "is" operator -- test whether two lvalues are references to each other -Status: Open +Status: Duplicate Type: Feature/Change Request Package: Variables related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Duplicate of bug #40051. Previous Comments: ------------------------------------------------------------------------ [2010-09-22 17:27:38] a_different_name at hotmail dot com 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.) ------------------------------------------------------------------------ [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 https://bugs.php.net/bug.php?id=52907&edit=1

« previous php.bugs (#200138) next »