> On Jan 28, 2020, at 17:55, Michael Cordover <m...@mjec.net> wrote:
> 
> On Tue, Jan 28, 2020, at 18:47, Ben Ramsey wrote:
>> If you take mutation off the table, then things become easier, IMO. We
>> only need two magic methods:
>> 
>> * __toInteger(): int
>> * __toFloat(): float
>> 
>> Then, in any mathematical context, PHP could call the appropriate
>> method and use the number returned in the calculation.
> 
> I don't think this is enough to make operator overloading useful, even 
> without mutation.
> 
> For example, the result of TimeInterval(1, 'ms') + TimeInterval(3, 'days') 
> requires more information that we'd get out of __toInteger or __toFloat, but 
> could still be a useful operation to perform, and ought to return a new 
> TimeInterval (not an int). There are many of these tagged-number types where 
> overloading would be helpful.


I just remembered this extension from a few years back. It’s no longer 
maintained, but it might help your efforts: 
https://github.com/php/pecl-php-operator

Cheers,
Ben

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to