note 101486 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Dec 2010 12:42:39 +0000 |
| Subject: | note 101486 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175075@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous Coward
----
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"
}