note 114059 added to class.splobjectstorage

From: Date: Tue, 07 Jan 2014 17:48:23 +0000
Subject: note 114059 added to class.splobjectstorage
Groups: php.notes 
Request: Send a blank email to php-notes+get-198142@lists.php.net to get a copy of this message
Note some inconsistent/surprising behavior in SplObjectStorage to preserve backwards compatibility. You can't properly use foreach with key/value syntax. <?php $spl = new SplObjectStorage (); $keyForA = new StdClass(); $keyForB = new StdClass(); $spl[$keyForA] = 'value a'; $spl[$keyForB] = 'value b'; foreach ($spl as $key => $value) { // $key is NOT an object, $value is! // Must use standard array access to get strings. echo $spl[$value] . "\n"; // prints "value a", then "value b" } // it may be clearer to use this form of foreach: foreach ($spl as $key) { // $key is an object. // Use standard array access to get values. echo $spl[$key] . "\n"; // prints "value a", then "value b" } ?> See https://bugs.php.net/bug.php?id=49967 ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/class.splobjectstorage.php Edit -- https://master.php.net/note/edit/114059 Del: integrated -- https://master.php.net/note/delete/114059/integrated Del: useless -- https://master.php.net/note/delete/114059/useless Del: bad code -- https://master.php.net/note/delete/114059/bad+code Del: spam -- https://master.php.net/note/delete/114059/spam Del: non-english -- https://master.php.net/note/delete/114059/non-english Del: in docs -- https://master.php.net/note/delete/114059/in+docs Del: other reasons-- https://master.php.net/note/delete/114059 Reject -- https://master.php.net/note/reject/114059 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198142) next »