|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41372 Internal pointer of source array resets during array copying
Submitted: 2007-05-12 08:32 UTC Modified: 2007-07-24 18:30 UTC
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: forjest at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Arrays related
PHP Version: 5.2.1, 4.4.7 OS: WinXP, Linux
Private report: No CVE-ID: None
 [2007-05-12 08:32 UTC] forjest at gmail dot com
Bug first appeared in 4.4.2. Version 4.4.1 works okay.
5.1.4, 5.2.1 has this bug too.
Seems algorithm of array copying was changed at 4.4.2 and 5.1.2 versions.
This behavior cause problems in unexpected situations such as error handling functions, when array pointer reseted due copying from another array which reference to it.

Reproduce code:
$Foo = array('val1', 'val2', 'val3');
$MagicInternalPointerResetter = $Foo;
Code describing unexpected results of this behavior listed here:

Expected result:
int(2) int(2)

Actual result:
int(2) int(0)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-12 10:10 UTC] forjest at gmail dot com
/*for simple case just wrap array in some array function. That will cause small overhead, but at least save your internal pointer*/
$Foo = array('val1', 'val2', 'val3');
$AllOkay = array_merge($Foo);

/*But to make immune running context for error handler function nothing helps, except ugly serialize/unserialize solution*/

function TestErrorHandler($severity, $message, $filename, $line,
    global $foo;
    $foo = unserialize(serialize($super_globals));

class Test  
     function run()  
          $Res = array('val1', 'val2', 'val3'); 
          HEY;//raise notice error 
$test = new Test(); 
$test-> run();
 [2007-05-16 13:01 UTC]
Duplicate of bug #40509.
 [2007-05-16 13:44 UTC] forjest at gmail dot com
I'm described problem, that is not foreach related. Just
1. Straight copy from one global scope variable to another
2. Copy from current runing context to global variable.

Not iterating local varibale after copying element of global array.
This is another bug, but may be from same "family".
And please remember another one
Problem appeared at 4.4.2 and 5.1.2 and was reported year ago...

May be I'm described duplicate of "This is expected and not going to be changed" bug instead of assigned 'foreach' bug?
 [2007-07-14 10:15 UTC]
Dmitry, check this out too, along with all those other reports about same issue.. :)
 [2007-07-24 18:30 UTC]
The bug is not related to #40509 and #40705
 [2007-07-24 18:30 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 13:01:27 2024 UTC