Bug #74724 [Opn->Ver]: current returns false but each returns value

From: Date: Mon, 23 Nov 2020 16:07:22 +0000
Subject: Bug #74724 [Opn->Ver]: current returns false but each returns value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230544@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: cmb@php.net Reported by: tell dot a dot name dot to dot me at gmail dot com Summary: current returns false but each returns value -Status: Open +Status: Verified Type: Bug Package: Variables related Operating System: win/linux PHP Version: 7.1.6 Block user comment: N Private report: N New Comment: The culprit is that we're resetting the internal pointer if it is beyond the valid range when duplicating the array[1]. [1] <https://github.com/php/php-src/blob/php-7.4.12/Zend/zend_hash.c#L2080-L2082> Previous Comments: ------------------------------------------------------------------------ [2017-06-09 08:21:08] 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#230544) next »