Re: Custom object equality
| From: | Dik Takken | Date: | Tue, 24 Oct 2023 12:57:55 +0000 |
| Subject: | Re: Custom object equality | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121456@lists.php.net to get a copy of this message | ||
On 23-10-2023 22:07, Jordan LeDoux wrote:
I don't quite follow. The interface would cause the engine to use the result of anNo, the interface would not cause anything to happen inequals()function on the object if it implements an interface as part ofzend_compare? Internally there is no==function, there is only the equivalent of<=>. To implement it ONLY for==would require a trapdoor of some kind in thedo_operationhandler that would also affect the way the existing extensions work, such as theDateTimeclass which implements a custom handler for thecomparehandler on the zend class entry.
zend_compare. It would simply serve to make explicit that an object has a custom implementation of a (set of) operators and that the implementing method can be called directly. So the developer can choose to either use the operator or call the implementing method on the object. Both styles would be supported and the following two expressions would be equivalent:
$a == $b
$a->equals($b)
(the method name is just an example)
Regarding your (Jordan's) RFC on the subject: The method call style would not yield readable code in this case, as the 'methods' are named after the operators. So that part of the RFC would need to change to make both styles work.
Regards,
Dik