Fix getting a property on an object casted to an array

This commit is contained in:
Fabien Potencier
2024-09-26 17:54:50 +02:00
parent be308bc5ac
commit 7d5269e100
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -1673,7 +1673,7 @@ final class CoreExtension extends AbstractExtension
$env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $item, $lineno, $source);
}
return $object->$item;
return isset($object->$item) ? $object->$item : ((array) $object)[(string) $item];
}
}
@@ -0,0 +1,13 @@
--TEST--
"." notation
--TEMPLATE--
{{ property.foo }}
{{ date.timezone }}
--DATA--
return [
'date' => new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris')),
'property' => (object) array('foo' => 'bar'),
]
--EXPECT--
bar
Europe/Paris