note 106698 deleted from splobjectstorage.offsetset by thiago

From: Date: Tue, 29 Nov 2011 12:56:48 +0000
Subject: note 106698 deleted from splobjectstorage.offsetset by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184754@lists.php.net to get a copy of this message
Note Submitter: dan dot lugg at gmail dot com ---- Unless someone can explain otherwise, it appears that the note; "SplObjectStorage::offsetSet() is an alias of SplObjectStorage::attach()", is not in fact the case, by which I mean offsetSet() does not call attach(). When you extends SplObjectStorage, using the array offset operator will of course invoke offsetSet(), but that doesn't in turn invoke attach(): <?php class ObjectStore extends SplObjectStorage{ public function attach($object, $data = null){ parent::attach($object, $data); var_dump($object, $data); } // other methods excluded for brevity } $store = new ObjectStore(); $store[new stdClass()] = new stdClass(); ?> One would expect the stdClass() objects to be dumped, but they're not. You need to explicitly tell offsetSet() to call attach(): <?php public function offsetSet($object, $data = null){ $this->attach($object, $data); } ?>

« previous php.notes (#184754) next »