php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36154 strange array cursor behavior during array assignment
Submitted: 2006-01-25 10:18 UTC Modified: 2006-01-30 16:04 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dmitriy dot buldakov at etadirect dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.4.2 OS: FreeBSD 5.3
Private report: No CVE-ID: None
 [2006-01-25 10:18 UTC] dmitriy dot buldakov at etadirect dot com
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#


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-25 10:46 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2006-01-25 13:26 UTC] dmitriy dot buldakov at etadirect dot com
Dear Sniper. 
I checked documentaion twice before the first reporting. 
So, I checked triply before this mail. 
 
There are no any phrase "cursor" or "pointer" on 
http://www.php.net/manual/en/language.types.array.php and 
http://www.php.net/manual/ru/language.types.array.php. 
And there is only one prase about "array assignment" -  
"You should be aware that array assignment always involves 
value copying. You need to use the reference operator to 
copy an array by reference" 
 
Also, there are no any phrase about cursor (or pointer) 
behavior in case of array assignment  on 
http://www.php.net/manual/en/ref.array.php and on reset, 
end, next, prev, current, pos, key, each functions 
description pages. 
 
Perhaps I am not skilled in text reading, but I am sure 
that the "not a bug" dose not described in a sensible 
section of the manual. 
 
Please check also.
 [2006-01-30 16:04 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"It also means that the internal array pointer used by current() and similar functions is reset."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 19:01:33 2025 UTC