On Thu, Jun 20, 2024, at 8:35 PM, Andreas Hennings wrote:
>> Ilija and I have been working on and off on an RFC for pattern matching since the early
>> work on Enumerations.
>
> I like what I see, a lot!
> One quick thought that came to my mind, regarding objects:
> Could we check method return values?
>
> if ($x is Countable { count(): 0 }) ...
> if ($p is Point { getX(): 3 }) ...
> if ($x is Stringable { __toString(): 'hello' }|'hello') ...
> while ($it is Iterator { valid(): true, current(): $value, next(): null }) ...
>
> Maybe it goes too far.
Much to my surprise, Ilija says that's technically possible. However, now that we have
property hooks the need for calling a method is far less, so we'd rather not in the interest of
simplicity for now. A future-RFC could probably add that if it's really needed, but I
don't think most languages support that anyway. (Need to verify.)
--Larry Garfield