请看一下
documentation
. Twig没有访问受保护的变量,这是不可能的,但由于它的实现,它将转换您的Twig代码,例如。
foo.bar
到
$foo.getBar()
并检查该方法是否存在,因此它能够“访问”受保护的变量
从…起
Twig
的文档
为了方便起见
富。酒吧
在PHP上执行以下操作
图层:
- check if foo is an array and bar a valid element;
- if not, and if foo is an object, check that bar is a valid property;
- if not, and if foo is an object, check that bar is a valid method (even if bar is the constructor - use __construct() instead);
- if not, and if foo is an object, check that getBar is a valid method;
- if not, and if foo is an object, check that isBar is a valid method;
- if not, and if foo is an object, check that hasBar is a valid method;
- if not, return a null value.
foo['bar']
另一方面,仅适用于PHP数组:
check if foo is an array and bar a valid element;
if not, return a null value.
source