#36154 [NEW]: strange array cursor behavior during array assignment
From: dmitriy dot buldakov at etadirect dot com
Operating system: FreeBSD 5.3
PHP version: 4.4.2
PHP Bug Type: Scripting Engine problem
Bug description: strange array cursor behavior during array assignment
Description:
------------
In case of assignment to a variable another variable that contains an
array with positioned cursor the old array loses cursor position but array
in new variable cathes it.
I think - the initial array ($a) cursor should be untouched.
The copied array ($c) cursor can be copied or reset, but its behavior
should be documented.
Reproduce code:
---------------
<?php
$a = array(1,2,3,4,5,6,7);
$b = $a;
next($a);
print 'next($a); ...'."\n";
print ' current($a) = '.current($a)."\n";
print ' current($b) = '.current($b)."\n";
$c = $a;
print '$c = $a; ...'."\n";
print ' current($a) = '.current($a)."\n";
print ' current($b) = '.current($b)."\n";
print ' current($c) = '.current($c)."\n";
?>
Expected result:
----------------
bash-3.00# php test.php
next($a); ...
current($a) = 2
current($b) = 1
$c = $a; ...
current($a) = 2
current($b) = 1
current($c) = 1
bash-3.00#
or
bash-3.00# php test.php
next($a); ...
current($a) = 2
current($b) = 1
$c = $a; ...
current($a) = 2
current($b) = 1
current($c) = 2
bash-3.00#
Actual result:
--------------
bash-3.00# php test.php
next($a); ...
current($a) = 2
current($b) = 1
$c = $a; ...
current($a) = 1
current($b) = 1
current($c) = 2
bash-3.00#
--
Edit bug report at http://bugs.php.net/?id=36154&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36154&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36154&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36154&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36154&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=36154&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36154&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36154&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36154&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36154&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36154&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=36154&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=36154&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36154&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36154&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36154&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36154&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36154&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36154&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36154&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36154&r=mysqlcfg
Thread (2 messages)
- dmitriy dot buldakov at etadirect dot com