Re: Object comparison

From: Date: Fri, 09 Nov 2012 13:52:39 +0000
Subject: Re: Object comparison
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-63795@lists.php.net to get a copy of this message
hi! On Fri, Nov 9, 2012 at 1:07 AM, Sara Golemon <pollita@php.net> wrote: > From: > http://php.net/manual/en/language.operators.comparison.php > > An object compared to anything which is not a bool, null, or object > should result in the object appearing to be greater than the other > operand. For example: > > $a = new stdClass(); > $b = new stdClass(); > > var_dump(null < $a); > var_dump(false < $a); > var_dump(true == $a); > var_dump($a == $b); > var_dump(0 < $a); > var_dump(1 < $a); // false > var_dump(2 < $a); // false > var_dump("foo" < $a); > var_dump("2" < $a); > var_dump(tmpfile() < $a); > > Based on docs, I expect all nine of these to yield true, however in > practice, the two marked "false" come out as false because the RHS > object is converted to an integer (1), contrary to the docs. > > Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted > others' thoughts. As stated by other before, comparing scalars and objects sound wrong in the 1st place. But I have seen way too many weird codes relying on weird things :). That's why I would not be in favor of changing anything in this area as some code out there may rely on that (have the feeling that object comparison has been like that since 5.0). Cheers, -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

« previous php.internals (#63795) next »