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 an `equals()` function on the object if it implements an
interface as part of `zend_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 the `do_operation` handler that would
also affect the way the existing extensions work, such as the `DateTime`
class which implements a custom handler for the `compare` handler on the
zend class entry.
No, the interface would not cause anything to happen in `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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php