note 106698 added to splobjectstorage.offsetset

From: Date: Tue, 29 Nov 2011 08:29:38 +0000
Subject: note 106698 added to splobjectstorage.offsetset
Groups: php.notes 
Request: Send a blank email to php-notes+get-184753@lists.php.net to get a copy of this message
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); } ?> ---- Server IP: 216.235.13.26 Probable Submitter: 216.121.232.204 ---- Manual Page -- http://www.php.net/manual/en/splobjectstorage.offsetset.php Edit -- https://master.php.net/note/edit/106698 Del: integrated -- https://master.php.net/note/delete/106698/integrated Del: useless -- https://master.php.net/note/delete/106698/useless Del: bad code -- https://master.php.net/note/delete/106698/bad+code Del: spam -- https://master.php.net/note/delete/106698/spam Del: non-english -- https://master.php.net/note/delete/106698/non-english Del: in docs -- https://master.php.net/note/delete/106698/in+docs Del: other reasons-- https://master.php.net/note/delete/106698 Reject -- https://master.php.net/note/reject/106698 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184753) next »