Hi,

Maybe it goes way to far, but there is a PECL-extension [1], that allows to
overload every(?) operator. However, it seems to be unmaintained for 6
years now and will probably not work anymore, but it may be usable as a
starting point. Python provides this too [2]

Regards,
Sebastian


[1] http://pecl.php.net/package/operator
[2] http://docs.python.org/2/reference/datamodel.html#special-method-names


2012/11/9 Christian Stoller <stol...@leonex.de>

> I would like to place a suggestion for comparing objects (I hope it is no
> problem, because this does not have anything to do with Sara's question -
> but it came to my mind when I read her mail). It would be a great feature
> if objects could be compared to other objects with ">", "<" and the other
> operators, like it is suggested in RFC https://wiki.php.net/rfc/comparable
> The DateTime class offers this feature - it would be nice if this could be
> made usable for userland classes/objects, too.
>
> Best regards
>
> Christian Stoller
>
>
> -----Original Message-----
> From: p...@golemon.com [mailto:p...@golemon.com] On Behalf Of Sara Golemon
> Sent: Friday, November 09, 2012 1:07 AM
> To: PHP internals
> Subject: [PHP-DEV] Object comparison
>
> 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
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>


-- 
github.com/KingCrunch

Reply via email to