Re: [RFC][VOTE] Objects as Keys

From: Date: Tue, 16 Dec 2014 20:52:09 +0000
Subject: Re: [RFC][VOTE] Objects as Keys
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-79743@lists.php.net to get a copy of this message
On 16 December 2014 18:50:06 GMT, Stanislav Malyshev <smalyshev@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.

« previous php.internals (#79743) next »