I got a BaseEntity class that implements the __call() and __get() functions. In my Twig template, I call entity.name (name doesn't exists in my entity class). The __get() method never gets called by Twig because of this line :
// Template.php line 381
if (isset($object->$item) || array_key_exists($item, $object)) {
isset function returns false, while echo($object->$item) returns the appropriate value.
And because of this line :
// Template.php line 406
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
Twig is trying to call $entity->$property() instead of $entity->$property, which is wrong.
Why is __call magic function supported but not __get ?
__get is supported, but you need to implement __isset as well as it is used by the isset() check. Read the documentation here: http://twig.sensiolabs.org/doc/recipes.html#using-dynamic-object-properties
Ok thanks!
Most helpful comment
__getis supported, but you need to implement__issetas well as it is used by theisset()check. Read the documentation here: http://twig.sensiolabs.org/doc/recipes.html#using-dynamic-object-properties