Fix: Facade Caller is never safe if the result is an object #426
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses an issue we were experiencing with Facades. We're upgrading an old project from Laravel 5.5 to 9.x that utilizes a few facades to generate code, specifically Laravel Collective's Form Builder. If you run this:
it will autoescape the tag. This had previously not escaped the HTML for years on older releases, producing forms as expected.
I did a few hours of troubleshooting and determined the cause was this line:
TwigBridge/src/Extension/Loader/Facade/Caller.php
Line 89 in f4968ef
Form.open()
returns anHtmlString
object which has a__toString()
method. The expectation is it would use that method to convert it to a String, but that doesn't happen becauseis_callable($result)
should never return true on an object. Instead, it is intended to be run as:Unfortunately, switching this one line to just use that instead of the combined
is_callable() && method_exists()
resulted in some unexpected behavior. The commit that added this check said it was to fix a PHP 8 TypeError, and my change to usuingis_object()
instead ofis_callable()
should satisfy the type errors, fix the bugs we're seeing, and maintain expected behavior.