On 16 December 2014 18:50:06 GMT, Stanislav Malyshev <smalys...@gmail.com> wrote: >Hi! > >> Explicit conversion is trivial, just call whatever method you like. >> Sure, you can't write (int)$obj, but $obj->toInt() is just as >> expressive. > >Exactly the same applies to __toString and whole ArrayAccess, yet we >still have them. Avoiding boilerplate code helps. Especially if >boilterplate code would look like: > >if(is_object($foo)) { > $foo_key = $foo->toInt(); >} else { > $foo_key = $foo; >} >$a[$foo] = 1; > >Doing it each time is annoying.
I was just confused by your statement that "explicit conversion is inacessible from userspace". But yeah, I guess with string keys you can just write $a[(string)$foo] and assume/hope it will do something meaningful whatever the type of $foo. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php