Skip the sandbox __toString check on arguments whose PHP parameter type cannot implicitly coerce to string#4823
Conversation
__toString check on arguments whose PHP parameter type cannot implicitly coerce to string
9d29273 to
8458a85
Compare
8458a85 to
ad1ac44
Compare
stof
left a comment
There was a problem hiding this comment.
For final classes implementing Stringable, would it make sense to try checking the policy at compile-time and mark it safe if we know that the policy allows casting them to string ?
This might help with the kind of logic currently done by Drupal to optimize the sandbox: #4820 (comment)
This is not possible as |
The sandbox visitor currently wraps every argument of every Twig callable with `CheckToStringNode.
As an optimization, we are now only wrapping when needed (based on the callable type hints). This is a conservative approach (untyped, mixed, string, array, iterable, object, Stringable, Traversable, self/static/parent and unknown class names all keep wrapping).
Here is a concrete before/after for template
{{ demo(a, b) }}under the sandbox, with the following signature on the PHP sidedemo(int $a, string $b):Before:
After