On 28.03.2020 at 22:21, Andrea Faulds wrote:

> Christoph M. Becker wrote:
>> (frankly, I would not have not supported __concat() at all).  Also,
>> overloaded operators should be programmed defensively, i.e. they should
>> not accept arbitrary arguments (how could that even work?), but only
>> those they can handle.  If implementations adhere to these "rules", I
>> don't see real issues.
>
> Consider a type implementing some kind of list. Perhaps someone would
> want to overload the + operator to mean adding an item to the list. If
> the list accepts any type of value as a valid item, then you have an
> example of an unconditional overload.

I had already considered this, and wrote immediately above the quote:

> If, for example, the + operator is overloaded to add something to a
> collection, the normal expectation that + is commutative is already
> violated.  Operator overloading should definitely not be used for
> "anything", but only for those rare cases which resemble math
> operations

Thanks,
Christoph

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to