Re: big reference bug in (at least) PHP 5.0.5
| From: | Antony Dovgal | Date: | Fri, 16 Sep 2005 12:40:09 +0000 |
| Subject: | Re: big reference bug in (at least) PHP 5.0.5 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-19049@lists.php.net to get a copy of this message | ||
On 16.09.2005 16:29, Ron Korving wrote:
My apologies for my DOM-mistake today, but right now I came across something that totally stunned me. It's a total paradox situation that just has to be one of the biggest bugs I've ever come across in PHP. Personally, I think it's rather high-priority because it's an engine problem, and not an issue with some extension. Here's the code: <?php $array = array(); for ($i=0; $i < 3; $i++)Ron, after the first foreach $item still points to the last element of $array (because you've used &$item syntax). The second foreach changes $item, but it *STILL* references the last element of $array, so it actually changes it instead. Try to change this part of the code: foreach ($array as $item)$array[] = array("foo" => $i);foreach ($array as &$item)$item["bar"] = $item["foo"] * 2;print_r($array); foreach ($array as $item)print_r($item);?>
print_r($item);to: foreach ($array as $blah)
print_r($blah);you'll see it yourself. I don't see any bugs here. -- Wbr, Antony Dovgal