Bug #74724 [Opn]: current returns false but each returns value
| From: | requinix@php.net | Date: | Fri, 09 Jun 2017 08:21:09 +0000 |
| Subject: | Bug #74724 [Opn]: current returns false but each returns value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209439@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74724&edit=1
ID: 74724
Updated by: requinix@php.net
Reported by: tell dot a dot name dot to dot me at gmail dot com
-Summary: each bug?
+Summary: current returns false but each returns value
Status: Open
Type: Bug
-Package: *General Issues
+Package: Variables related
Operating System: win/linux
PHP Version: 7.1.6
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2017-06-09 08:00:07] 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 06:07:38] 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;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74724&edit=1