Re: [RFC][VOTE] Objects as Keys

From: Date: Tue, 16 Dec 2014 11:05:40 +0000
Subject: Re: [RFC][VOTE] Objects as Keys
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-79711@lists.php.net to get a copy of this message
> > 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/

« previous php.internals (#79711) next »