On 11/08/2012 05:07 PM, Sara Golemon 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.

-Sara


You seem to be reporting a bug ("contrary to the docs"), but you might be suggesting that the doc be corrected (since doc and behaviour should always match).

I would suggest being very careful about implementing something as central as a change to how comparisons are made, that ought to be approached with great caution because it has the potential for breaking a huge amount of existing code.

[It does occur to me however, simply as a point of interest, that objects traditionally have both a constructor and a destructor, and the idea of objects also having a comparator makes a certain amount of sense; a default object comparator might implement the currently defined comparisons while allowing derived classes to override the default behaviour and leaving comparisons not involving objects undisturbed.]

Comparing objects to scalars is really an apples/oranges comparision to begin with.



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

Reply via email to