On 07/12/2020 15:26, Larry Garfield wrote:
Assuming it's feasible to do, what do people feel about supporting that?  IMO, 
cases(), from(), and values() need to be kept no matter what as they're more 
self documenting and can be passed around as callables.  So the question is 
just whether we should also try to add casting as an alias to those operations.


From my experience answering questions about SimpleXML on Stack Overflow, I can confirm that people find magic behaviour of (string) hard to discover and understand, and it's not uncommon to see someone write $foo->__toString() because they're more familiar with methods.

That's even more true for other casts, e.g. (int)$foo and (float)$foo, which can be supported by built-in classes but not userland ones, so are even less discoverable.

I can see the appeal of overloading cast syntax, but I would personally be on the "just use explicit methods" side.

Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

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

Reply via email to