php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5052 Bug in ref-count(?) working with nested foreach() on copied var
Submitted: 2000-06-15 08:26 UTC Modified: 2000-08-11 06:18 UTC
From: waldschrott at kiffen dot de Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (15/06/2000) OS: win2000 / perhaps all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: waldschrott at kiffen dot de
New email:
PHP Version: OS:

 

 [2000-06-15 08:26 UTC] waldschrott at kiffen dot de
1.) Serious bug, nesting of foreach() does not work if the nested foreach() works with a copy of the same var.
Code below results in...
"b0a0a1a2a3a4a5a6"
instead of "b0a0a1a2a3a4a5a6b1a0a2....b6a0a1a2a3a4a5a6" foreach() copies the array it uses to use the pointer internally, why doesn?t nesting work?
That?s a bug that will definitively affect users...


$b=$a=array(0,1,2,3,4,5,6);
foreach($b AS $test)	{
	print 'b'.$test;
	foreach ($a AS $test2)	{
		print 'a'.$test2; } }

2.) Once again this can be "fixed" using this strange snipplet:
$b=&$b; 
Which should BTW, (in my eyes) not work, because $b=&array(0,1,2,3,4,5,6) does not work too.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-27 19:48 UTC] waldschrott@php.net
marked 5270 as a duplicate of this one, changed type
 [2000-08-11 06:11 UTC] andi@php.net
This specific problem should be fixed in the current CVS now.
 [2000-08-11 06:18 UTC] waldschrott@php.net
I?ll give it a try, please tell me... did it has anything to
do with ref-count at all?
Why did $b=&$b work then it actually should do nothing but
overwriting itself with exactly the same information....
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 18:01:28 2024 UTC