-
-
Notifications
You must be signed in to change notification settings - Fork 205
Closed
Description
At the moment the list language construction cannot be used directly in foreach (after as statement) which is rather a bug in https://github.com/PHPCompatibility/PHPCompatibility than an issue with PHP incompatibility, since the construction is available as of PHP 5.5 (see https://www.php.net/manual/en/migration55.new-features.php#migration55.new-features.foreach-list).
test.php:
<?php
$a = [
[1, 2],
[1, 2],
];
foreach ($a as list($key, $value)) {
assert($key === 1);
assert($value === 2);
}
foreach ($a as [$key, $value]) {
assert($key === 1);
assert($value === 2);
}./vendor/bin/phpcs ./test.php --standard=PHPCompatibility -s
FILE: test.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8 | ERROR | Function name, class name, namespace name or constant name can not be reserved keyword 'list' (since version all)
| | (PHPCompatibility.Keywords.ForbiddenNames.listFound)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 151ms; Memory: 10MB
Reactions are currently unavailable