Fix wrong array index

This commit is contained in:
Fabien Potencier
2025-01-31 21:30:50 +01:00
parent a5ebdfe1f5
commit b0399992be
3 changed files with 10 additions and 3 deletions
+1
View File
@@ -1,5 +1,6 @@
# 3.20.0 (2025-XX-XX)
* Fix wrong array index
* Bump minimum PHP version to 8.1
# 3.19.0 (2025-01-28)
-3
View File
@@ -112,9 +112,6 @@ class ArrayExpression extends AbstractExpression
}
if ($nextIndex !== $key) {
if (\is_int($key)) {
$nextIndex = $key + 1;
}
$compiler
->subcompile($pair['key'])
->raw(' => ')
+9
View File
@@ -50,6 +50,11 @@ Twig supports array notation
{{ does_not_exist[0]|default('ok') }}
{{ does_not_exist[0].does_not_exist_either|default('ok') }}
{{ does_not_exist[0]['does_not_exist_either']|default('ok') }}
{# indexes are kept #}
{% set trad = {194:'ABC',141:'DEF',100:'GHI',170:'JKL',110:'MNO',111:'PQR'} %}
{% set trad2 = {'194':'ABC','141':'DEF','100':'GHI','170':'JKL','110':'MNO','111':'PQR'} %}
{{ trad == trad2 ? 'OK' : 'KO' }}
--DATA--
$objectStorage = new SplObjectStorage();
$object = new stdClass();
@@ -84,6 +89,8 @@ bar
ok
ok
ok
OK
--DATA--
return ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'array_access' => new \ArrayObject(['a' => 'b']), 'object' => new stdClass()]
--CONFIG--
@@ -117,3 +124,5 @@ bar
ok
ok
ok
OK