yiisoft / yii2-twig

Yii 2 Twig extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
137 stars 62 forks source link

Incompatible with Twig 2.7.2 #115

Closed nnrudakov closed 4 years ago

nnrudakov commented 5 years ago

Update composer. I have Admin model with string role attribute. I have an empty model in create form. My template fragment:

{% if model.role != constant('app\\models\\Admin::ROLE_SUPERADMIN') %}
    {{ form.field(model, 'role').dropDownList(roles)|raw }}
{% endif %}

And in condition I've got an error:

Twig\Error\RuntimeError
An exception has been thrown during the rendering of a template ("Calling unknown method: app\models\Admin::role()").
↵
Caused by: Unknown Method – yii\base\UnknownMethodException

It works with Twig 2.6.2.

Additional info

Q A
Yii version 2.0.16.1
Yii Twig version 2.2.1
Twig version 2.7.2
PHP version 7.0+
Operating system Ubuntu
machour commented 5 years ago

Confirmed, it seems that our tests broke with Twig 2.7.0. It might have something to do with the security fix to the sandbox: https://github.com/twigphp/Twig/blob/2.x/CHANGELOG#L75

nnrudakov commented 4 years ago

Error appears when environment option strict_variables is true. Twig trying to call a method if property is null which returns __get() and __isset() of model. There is no error if strict_variables is false. Checked on Twig v2.12.1 also.