New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor each() to foreach() for compatibility with PHP 7.2 #1377
Conversation
An RFC for PHP 7.2 has been voted on for inclusion in PHP 7.2. It proposes to deprecate the `each()` function for PHP 7.2 and removes it in 8.0. The `each()` function is exponentially slower and wastes resources vs `foreach()`, so we're refactoring it now whether PHP 7.2 finally does adopt it or not.
6da62e5
to
19e16d4
Compare
👍 |
1 similar comment
👍 |
Note: our various imported vendor packages we leverage will require updates; will cross that bridge when they push new versions. |
@drbyte, How would you suggest tackling instances where there is no while loop involved? Examples: b) list(, $value) = each($foo) c) list($key, ) = each($foo) |
I'm not aware of any such use cases in actual Zen Cart code, old or new. Reading http://php.net/manual/en/function.each.php and http://php.net/manual/en/function.list.php offer some insight, particularly the fact that |
Thanks. Came across these elsewhere and was looking for correct solutions when I found your post here. For the record,
... and list($key) = each($foo) is equivalent to Example C |
Agreed. Thanks for posting these. It's unfortunate there's no shorter and equally expressive version as |
I'm using php7.2 for development, PHPstorm marks "each" as deprecated. |
We were discussing that earlier this week. We'll be tagging a new release. |
An RFC for PHP 7.2 has been voted on for inclusion in PHP 7.2. It proposes to deprecate the
each()
function for PHP 7.2 and removes it in 8.0.The
each()
function is exponentially slower and wastes resources vsforeach()
, so we're refactoring it now whether PHP 7.2 finally does adopt it or not.Things to note when refactoring:
foreach()
doesn't need areset()
to be called before it runs, so those can be removed.list()
call:a)
while(list($key, $value) = each($foo))
This becomes
foreach($foo as $key => $value)
b)
while(list(, $value) = each($foo))
This becomes
foreach($foo as $value)
c)
while(list($key, ) = each($foo))
This becomes
foreach($foo as $key => $value)