Skip to content
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

Math operations with non-numeric strings in PHP8 causes fatal error #3454

Closed
LoranRendel opened this issue Dec 15, 2020 · 4 comments
Closed

Comments

@LoranRendel
Copy link

In PHP8 conversion of non-numeric string to number is considered fatal error.

Following example will throw a fatal error:

file.php

$twig = new Environment(new FilesystemLoader(__DIR__));
$twig->display('Page.twig', ['test_var' => 'string']);

template.html.twig

{{ test_var + 1 }}

Result:

Fatal error: Uncaught Error: Unsupported operand types: string + int
in /vendor/twig/twig/src/Environment.php(358) : eval()'d code on line 37
@michaljusiega
Copy link
Contributor

michaljusiega commented Dec 15, 2020

This is expected behaviour since PHP 8.0.
See https://wiki.php.net/rfc/arithmetic_operator_type_checks or php/php-src#5331

@LoranRendel
Copy link
Author

Yes, I know that, but Twig probably should protect from these errors, and it is hard to find source of error by eval()'d code on line 37.

@stof
Copy link
Member

stof commented Dec 15, 2020

Well, adding type checks around each arithmetic operation in compiled twig templates will affect performance for all templates.

Note that if you configure the Twig cache for compiled templates, the compiled templates won't be eval'ed anymore but loaded from the cache folder, which makes the stack trace easier to analyze (as you can open the file in the cache folder to see which template is in it)

@fabpot
Copy link
Contributor

fabpot commented Jan 1, 2021

Closing as I don't think there is anything we can do.

@fabpot fabpot closed this as completed Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants