php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74724 current returns false but each returns value
Submitted: 2017-06-09 06:07 UTC Modified: 2017-06-09 08:21 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: tell dot a dot name dot to dot me at gmail dot com Assigned:
Status: Open Package: Variables related
PHP Version: 7.1.6 OS: win/linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-06-09 06:07 UTC] tell dot a dot name dot to dot me at gmail dot com
Description:
------------
<?php
$arr = ['a', 'b', 'c'];
var_dump(current($arr));
echo '--------aaaaaa--------', PHP_EOL;
var_dump(end($arr));
var_dump(next($arr));

$abc = $arr;

echo '--------bbbbbbb--------', PHP_EOL;

var_dump(current($abc)); // false
var_dump(current($abc)); // false
var_dump(each($abc)); // not false???
var_dump(each($abc)); // not false???
var_dump(each($abc)); // not false???
echo '--------cccccccc--------', PHP_EOL;

Test script:
---------------
<?php
$arr = ['a', 'b', 'c'];
var_dump(current($arr));
echo '--------aaaaaa--------', PHP_EOL;
var_dump(end($arr));
var_dump(next($arr));

$abc = $arr;

echo '--------bbbbbbb--------', PHP_EOL;

var_dump(current($abc)); // false
var_dump(current($abc)); // false
var_dump(each($abc)); // not false???
var_dump(each($abc)); // not false???
var_dump(each($abc)); // not false???
echo '--------cccccccc--------', PHP_EOL;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-09 08:00 UTC] sjon at hortensius dot net
Looking at https://3v4l.org/dGZbf the reporter considers the difference between php5 & php7 to be a bug

However, I think this is caused by the changes made for https://wiki.php.net/rfc/php7_foreach The documentation could be updated; but each is already marked as deprecated
 [2017-06-09 08:21 UTC] requinix@php.net
-Summary: each bug? +Summary: current returns false but each returns value -Package: *General Issues +Package: Variables related
 [2017-06-09 08:21 UTC] requinix@php.net
The point is that current($abc) returns false but each($abc) returns a value. It's inconsistent: either the pointer is reused and both return false, or the pointer is reset for the new variable and both return values.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 26 17:01:27 2019 UTC