Re: [RFC] Internal operator overloading and GMP improvements
| From: | Nikita Popov | Date: | Sun, 09 Jun 2013 14:15:19 +0000 |
| Subject: | Re: [RFC] Internal operator overloading and GMP improvements | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-67666@lists.php.net to get a copy of this message | ||
On Sun, Jun 9, 2013 at 3:37 PM, Zeev Suraski <zeev@zend.com> wrote:
> What I meant by cumulativity in that context is really commutativity J
> Fixed (and also added transitivity).
>
>
>
> In other words, operands that are commutative in PHP (like addition,
> multiplication, etc.) – one should not overload for domains where they’re
> not commutative.
>
>
>
> Zeev
>
Why? For example matrix multiplication is not commutative, but I would
still consider writing $matrixA * $matrixB a valid application of
overloading. Non-commutative multiplication operations aren't uncommon
(that's why a mathematical ring only requires the addition operator to be
commutative).
The same also applies the other way around: For example PHP's default +
operator is *not* commutative (when used on arrays) and both + and * are
non-associative and non-distributive (floating point arithmetic), but you'd
probably still expect those properties from an overloaded +/- operator.
That's why I'm not sure it makes sense to have "too strict" definitions for
what is a valid overload and what isn't. I think "limited to cases where
there are clear definitions to the behavior of all overloaded operators"
and "should be for mathematical use cases only" are enough as guidelines :)
Thanks,
Nikita