Hi Rowan.

I agree that this makes sense. However, as someone else pointed out, one problem with interfaces is that they constrain the types that may be used.

We have our own Money, Percentage, PricePerMm, etc. types that we'd like to define operators for, how can you define an interface in PHP that accommodate types that are unknown to the PHP implementors?

If we had support for generics, we could have defined generic interfaces, but we don't so we can't.

Regards,

Terje

Hi Terje,

I think both of your examples are compatible with the idea of grouped
operators, as long as we don't constrain a type to implement all
operators with the same right-hand side.
...
If this operator was implemented in isolation, it would again be
drifting into domain-specific language territory. (I don't personally
have a problem with that, but many people vocally object to it.)

However, it could easily be made part of a consistent set of
arithmetic operators:

On class Money:

Money + Money => Money
Money - Money => Money
Money * int => Money
Money / int => Money
int * Money => Money
int / Money => Error
Money * Percentage => Money
Money / Percentage => Money
Percentage * Money => Money
Percentage / Money => Error
Optionally, on class Percentage:

Percentage + Percentage => Percentage
Percentage - Percentage => Percentage
Percentage* int => Percentage
Percentage / int => Percentage



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

Reply via email to