On Sun, 03 Oct 2010 15:37:41 +0100, Johannes Schlüter
<johan...@schlueters.de> wrote:
On Sun, 2010-10-03 at 15:21 +0100, Gustavo Lopes wrote:
I actually see no reason why we shouldn't expose the compare overload we
already have for internal classes to userspace classes.
For internal classes it is needed, as they extend zend_object with
custom information we don't find in hash tables etc. so without the
internal handler we can't decide whether two objects are equal or not.
However, the patch goes much further than this and, even if that
direction were desired, it takes, in my opinion, the wrong options in
the
details I've mentioned.
For userspace-defined classes the equal and other comparison operation
are clearly defined. (Well, maybe some of the conversions aren't always
that clear, but still follow rules)
When adding this feature the comparison operators change their
meaning ...
You raise a fair point -- the motivation to override the comparison
operator for internal classes is indeed bigger because the state is not in
the usual places. However:
* The functionality already exists; comparison operators already have
their meaning "changed" (read: user-defined) for some objects.
* I'd argue the current behavior (comparing classes and properties) is of
limited use for equality. It's common to lazy-load the properties of the
objects, which makes the current comparison behavior unreliable.
* The current behavior for >, <, etc. is completely useless. It's
unpredictable and it doesn't even establish a total order:
$a = new stdclass;
$a->prop = null;
$b = new stdclass;
$b->prop2 = null;
var_dump($a > $b); //false
var_dump($a == $b); //false
var_dump($b > $a); //false
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php