On 6 May 2022 23:16:37 BST, Jordan LeDoux <jordan.led...@gmail.com> wrote: >I'm not sure at this point how voters think objects and operators should >work together into the future. I'd like to see if anyone is willing to have >high-level discussion about the ideas, instead of picking at the >implementation or details of a particular RFC.
Hi Jordan, I like Larry's "4 levels", but I've been thinking that there's some existing functionality in PHP which takes a different direction: rather than overloading *operators*, the language lets you overload *behaviour*. We have magic methods like __get and __call, and interfaces like Iterator, Countable, and ArrayAccess. Some hook into a particular function, or even operator, but they're generally described in terms of what they do, not what they look like, if you see what I mean. From that point of view, overloading comparison and equality *behaviour* makes sense - it could affect not just the == and <=> operators, but things like in_array() and sort(). I think this distinction is more pronounced in PHP than some languages, because the standard library isn't "self-hosted": a sort() call doesn't literally compile to a call to $a <=> $b It's less obvious how that applies to mathematical operators - should implementing "addition" allow an object to be used with array_sum() perhaps? And what about deriving one operation from another, e.g. $foo*3 running $foo+$foo+$foo, or $foo**3 running $foo*$foo*$foo? I don't really have a conclusion here, I just wanted to throw it out there as a different mental model to consider. Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php