Re: RFC: Comparable interface

From: Date: Sun, 03 Oct 2010 18:02:13 +0000
Subject: Re: RFC: Comparable interface
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-49852@lists.php.net to get a copy of this message
hi Gustavo, On Sun, Oct 3, 2010 at 7:34 PM, Gustavo Lopes <glopes@nebm.ist.utl.pt> wrote: > 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 It may be why Stas' proposal could fit better, a comparable interface. As there is then no confusion with undefined and useless behaviors with normal comparison ops. Cheers, -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

« previous php.internals (#49852) next »