ID: 28165 Comment by: john at pinesoft dot co dot uk Reported By: daniel at rozsnyo dot com Status: Suspended Bug Type: Feature/Change Request Operating System: * PHP Version: 5.0.* New Comment:
problem still evident in 5.2.1 <?php $obj = new stdClass; var_dump($obj == 1); ?> Previous Comments: ------------------------------------------------------------------------ [2005-12-16 17:52:43] php at jort dot net I updated form 5.0.4 to 5.1.1 and encountered this problem. I use == and try to compare a DOM node value with a class property. What's the difference between these versions? ------------------------------------------------------------------------ [2004-04-29 21:07:49] daniel at rozsnyo dot com OK, I have a "temporary" solution (because i wanted to compare the object references): Instead of this: echo (in_array($x,$a)) ? 'There' : 'NOT there'; I must use this: echo (in_array($x,$a,TRUE)) ? 'There' : 'NOT there'; This way the PHP uses the '===' operator which is OK for me. ad the '==' operator) The notice of "Notice: Object of class A could not be converted to integer in..." is a bit ambiguous - I spent a day searching how to make an integer from an object. Anyway, the '==' works in PHP, but generates these notices - what if I really want to compare the objects by value? ------------------------------------------------------------------------ [2004-04-29 20:53:29] hans at velum dot net Using '===' instead of '==' will work, but is semantically different, right? $a === $b : are object references the same? i.e. are $a and $b the same instance. $a == $b : do the contents match? i.e. do all the variables in object $a have the same values as the vars in object $b. If '==' is going to be changed to mean something else, then I think PHP5 needs an __equals() method so that object contents comparison can be accomplished. ------------------------------------------------------------------------ [2004-04-26 21:11:55] rozsnyo at kn dot vutbr dot cz The notices are also generated on comparison operator (==) This code: <?php class A { public $p; function __construct($ip) { $this->p = $ip; } } $x = new A(1); $y = $z = new A(2); echo '$x,$y is ' , ( ($x == $y) ? 'equal' : 'not equal[right]' ), '<br>'; echo '$x,$y is ' , ( ($x === $y) ? 'identical' : 'not identical[right]' ), '<br>'; echo '$z,$y is ' , ( ($z == $y) ? 'equal[right]' : 'not equal' ), '<br>'; echo '$z,$y is ' , ( ($z === $y) ? 'identical[right]' : 'not identical' ), '<br>'; ?> Produces: $x,$y is Notice: Object of class A could not be converted to integer in C:\www\default\test\index.php on line 11 Notice: Object of class A could not be converted to integer in C:\www\default\test\index.php on line 11 not equal[right] $x,$y is not identical[right] $z,$y is Notice: Object of class A could not be converted to integer in C:\www\default\test\index.php on line 13 Notice: Object of class A could not be converted to integer in C:\www\default\test\index.php on line 13 equal[right] $z,$y is identical[right] At least, please remove the notification and fix the in_array and also the array_search function (seems that both share the same algorithm - always two notices as two objects are compared) - the right solution would be to use the === operator in these functions when the needle is an object. This bug is still about: http://www.php.net/ChangeLog-5.php Changed array_search() to accept also objects as a needle. (Moriyoshi) ------------------------------------------------------------------------ [2004-04-26 20:39:34] [EMAIL PROTECTED] There are no plans for this. Maybe in PHP 6. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/28165 -- Edit this bug report at http://bugs.php.net/?id=28165&edit=1