note 101486 added to control-structures.foreach

From: Date: Mon, 20 Dec 2010 09:47:29 +0000
Subject: note 101486 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-175074@lists.php.net to get a copy of this message
In response to Mark Rose's post on Dec. 15th, that bug can be remedied by adding unset($bar); after the offending foreach{} block. (That bug is still quite a nasty bugger, thank you for finding and warning of it!) <?php $foo = array('one', 'two', 'three'); foreach ($foo as &$bar){ // no-op } unset($bar); // ^^ Add the above line to fix reused reference error ^^ var_dump($foo); foreach ($foo as $bar){ // no-op } var_dump($foo); ?> Produces: array(3) { [0]=> string(3) "one" [1]=> string(3) "two" [2]=> string(5) "three" } array(3) { [0]=> string(3) "one" [1]=> string(3) "two" [2]=> string(5) "three" } ---- Server IP: 64.71.164.2 Probable Submitter: 67.164.102.252 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/101486 Del: integrated -- https://master.php.net/note/delete/101486/integrated Del: useless -- https://master.php.net/note/delete/101486/useless Del: bad code -- https://master.php.net/note/delete/101486/bad+code Del: spam -- https://master.php.net/note/delete/101486/spam Del: non-english -- https://master.php.net/note/delete/101486/non-english Del: in docs -- https://master.php.net/note/delete/101486/in+docs Del: other reasons-- https://master.php.net/note/delete/101486 Reject -- https://master.php.net/note/reject/101486 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175074) next »