-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Rely on reflection to access null properties #4425
Conversation
940ea01
to
f023cec
Compare
f023cec
to
5e793c3
Compare
5e793c3
to
e4eb3ce
Compare
c186115
to
d8f39e6
Compare
PR updated with a simpler and more performant approach, that makes DateTimeInterface a special case (because it is). |
d8f39e6
to
aca2914
Compare
5e1b6fe
to
ca54737
Compare
ca54737
to
6952a4a
Compare
6952a4a
to
5cd1ff1
Compare
Thank you @nicolas-grekas. |
@@ -1642,7 +1642,7 @@ public static function getAttribute(Environment $env, Source $source, $object, $ | |||
|
|||
// array | |||
if (Template::METHOD_CALL !== $type) { | |||
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; | |||
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item = (string) $item; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string casting breaks my ArrayAccess object using objects as keys, when using myCollection[object]
in twig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arf. Can you please submit a fix as a PR together with a test case?
This PR was merged into the 3.x branch. Discussion ---------- Fix ArrayAccess with objects as keys fixes #4476 The bug was introduced in 3.15 via #4425 (comment) Commits ------- 32a75b7 Fix ArrayAccess with objects as keys
Benchmark like https://gist.github.com/arnaud-lb/c4235164fb41e11672aa670da8fa4fc7 (which were done for another use case but is still relevant here) prove that using reflection instead of array-casts is significantly faster for accessing properties.
Checking for dynamic properties is done with property_exists.