Re: [RFC][VOTE] Objects as Keys

From: Date: Tue, 16 Dec 2014 18:44:20 +0000
Subject: Re: [RFC][VOTE] Objects as Keys
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-79739@lists.php.net to get a copy of this message
On 16 December 2014 18:14:27 GMT, Stanislav Malyshev <smalyshev@gmail.com> wrote: >Hi! > >> I was previously in favour of this, but it’d prevent actual indexing > >No, of course it won't - if we ever introduce indexing objects (which >probably will require rewrite of the HashTable, any takers?) it would >be >very easy to index any object that does not implement __hash without >any >BC problem, and convert all those implementing __hash to "return $this" >if desired. > >> by objects in future, and I can’t think of any use cases which >> aren’t better solved by explicitly converting to a string/integer. > >There's no implicit conversion, and explicit one is a) inacessible in >userspace for anything but string and b) annoying for the same reasons >for which __toString exists. Explicit conversion is trivial, just call whatever method you like. Sure, you can't write (int)$obj, but $obj->toInt() is just as expressive.

« previous php.internals (#79739) next »