Re: [RFC][VOTE] Objects as Keys

From: Date: Tue, 16 Dec 2014 11:34:23 +0000
Subject: Re: [RFC][VOTE] Objects as Keys
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-79717@lists.php.net to get a copy of this message
Hi, All I can say is that the lack of this feature is one of the main reasons why Doctrine doesn't fully work with composite keys. With this enhancement it would now become possible to implement a proper IdentityMap. []s, On Dec 16, 2014, at 9:05 AM, Andrea Faulds <ajf@ajf.me> wrote: >> >> On 16 Dec 2014, at 10:52, Andrea Faulds <ajf@ajf.me> wrote: >> >> Exactly. If I were to do this: >> >> <?php >> class Foo { >> public $foo; >> function __construct($foo) { >> $this->foo = $foo; >> } >> function __toKey() { >> return $this->foo; >> } >> } >> $arr = []; >> $arr[] = new Foo(1); >> var_dump($arr); >> >> I would get this: >> >> array(1) { >> [0]=> >> int(1) >> } > > Er, a correction… the example should’ve been something like this: > > $arr = []; > $arr[new Foo(1)] = NULL; > > Producing this: > > array(1) { > [1]=> > NULL > } > > Obviously, it has no effect on values, only keys, sorry! > > -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.internals (#79717) next »