php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39556 Referenced Arrays with KEY and CURRENT
Submitted: 2006-11-19 22:15 UTC Modified: 2006-11-20 09:24 UTC
From: randallgirard at hotmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.4 OS: Linux?
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: randallgirard at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-11-19 22:15 UTC] randallgirard at hotmail dot com
Description:
------------
once an array is referenced elsewhere, it seems that KEY and CURRENT do not work as expected.

I'm not sure of the version on the webhost I'm using,

Reproduce code:
---------------
$arr = array('0', '1', '2', '3');

reset($arr);

print('Direct ');
print('NEXT: '.next($arr).' ');
print('NEXT: '.next($ref).' ');
print('NEXT: '.next($ref).' ');
print('KEY: '.key($arr).' ');
print('CURRENT: '.current($arr).' ');
print("<br><br>\n");

$ref =& $arr;
reset($arr);

print('Direct ');
print('NEXT: '.next($arr).' ');
print('NEXT: '.next($ref).' ');
print('NEXT: '.next($ref).' ');
print('KEY: '.key($arr).' ');
print('CURRENT: '.current($arr).' ');
print("<br><br>\n");

reset($ref);

print('Referended ');
print('NEXT: '.next($ref).' ');
print('NEXT: '.next($ref).' ');
print('NEXT: '.next($ref).' ');
print('KEY: '.key($ref).' ');
print('CURRENT: '.current($ref).' ');
print("<br><br>\n");


Expected result:
----------------
Direct NEXT: 1 NEXT: 2 NEXT: 3 KEY: 3 CURRENT: 3 

Direct NEXT: 1 NEXT: 2 NEXT: 3 KEY: 3 CURRENT: 3 

Referended NEXT: 1 NEXT: 2 NEXT: 3 KEY: 3 CURRENT: 3 

Actual result:
--------------
Direct NEXT: 1 NEXT: 2 NEXT: 3 KEY: 3 CURRENT: 3 

Direct NEXT: 1 NEXT: 2 NEXT: 3 KEY: 0 CURRENT: 0 

Referended NEXT: 1 NEXT: 2 NEXT: 3 KEY: 0 CURRENT: 0 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-20 09:24 UTC] tony2001@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 15:01:33 2024 UTC