What happened?
Description
Twig 3.23 shipped optional chaining (null-safe operator), which should work in Craft 5.10, since that version bumped the Twig dependency. However, it looks like Craft's extension of the Twig environment breaks optional chaining completely.
{% set user = null %}
Hello {{ user?.name }}
{% set user = null %}
Hello {{ user?.getFullName() }}
Both of those result in a runtime error:
Impossible to access an attribute ("name") on a null variable in "path/to/template" at line 2.
While the template compiles correctly, the null-safe operator is apparently silently dropped. I checked the compiled template – the PHP line corresponding to that part of the template is completely identical, whether I use the null-safe operator or not.
This template works as expected in the playground. That's why it's probably an issue in Craft's implementation.
Craft CMS version
5.10.7
PHP version
8.5
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
What happened?
Description
Twig 3.23 shipped optional chaining (null-safe operator), which should work in Craft 5.10, since that version bumped the Twig dependency. However, it looks like Craft's extension of the Twig environment breaks optional chaining completely.
{% set user = null %} Hello {{ user?.name }}{% set user = null %} Hello {{ user?.getFullName() }}Both of those result in a runtime error:
While the template compiles correctly, the null-safe operator is apparently silently dropped. I checked the compiled template – the PHP line corresponding to that part of the template is completely identical, whether I use the null-safe operator or not.
This template works as expected in the playground. That's why it's probably an issue in Craft's implementation.
Craft CMS version
5.10.7
PHP version
8.5
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions