Bug #67608 [NEW]: PHP Bug when reusing variables by references
| From: | rafavega at gmail dot com | Date: | Fri, 11 Jul 2014 15:21:59 +0000 |
| Subject: | Bug #67608 [NEW]: PHP Bug when reusing variables by references | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-186566@lists.php.net to get a copy of this message | ||
From: rafavega at gmail dot com
Operating system: Debian, MacOS
PHP version: 5.5.14
Package: *General Issues
Bug Type: Bug
Bug description:PHP Bug when reusing variables by references
Description:
------------
What this code should do, is to take the $lines array and delete the 2B
value, but it doesnât work like that, and is because it get crash when
you use the $items variable in the second foreach and you already used
it as a referece variable, even if you clean the $items variable with an
empty array as you see in the code.
Just if you change the name or the $items variable in the second foreach
it works fine.
Test script:
---------------
$lines = array(
'1' => array(
'1A'
),
'2' => array(
'2A',
'2B',
'2C'
)
);
foreach($lines as &$items){
foreach($items as $key => $value){
if($value=='2B') unset($items[$key]);
}
}
$items = array();
foreach($lines as $key => $items){
print_r($items);
}
Expected result:
----------------
array(
'1A'
)
array(
'2A',
'2C'
)
Actual result:
--------------
array(
'1A'
)
array(
'1A'
)
--
Edit bug report at https://bugs.php.net/bug.php?id=67608&edit=1
--