On Thu, Nov 8, 2012 at 7:07 PM, Sara Golemon <poll...@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.
>


Hi Sara,

I believe the documentation is failing us here.

>From what I see the docs are pretty lacking in what should be expected
in terms of object comparison.

For example, the page at http://php.net/types.comparisons doesn't even
include objects in the comparison table.

Of course by looking at the "Comparison with Various Types" table at
http://php.net/language.operators.comparison one gets the impression
that the "Operand 1" and "Operand 2" columns are to signify LVALUE and
RVALUE operands, respectively. Obviously this isn't the case and the
documentation just fails us here.

var_dump(new stdclass < 1, newstdcalss > 1, 1 < new stdclass, 1 > new
stdclass); // false, false, false, false

Clearly there are cases when the object can be neither less-than nor
greater-than an operand in a comparison.

The statement "object is always greater" in that table is misleading
and doesn't tell us the whole truth.

For example,
class foo { public function __toString() { return ''; } }
var_dump(new foo < '', new foo > '', '' < new foo, '' > new foo); //
false, false, false, false

Obviously there are more complex cases where the object may not pan
out to be greater than a non-object type that the documentation fails
to address.

> -Sara
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to