mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-24 23:16:26 +00:00
Fix getting a property on an object casted to an array
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user