我在代码中发现了这个,它意味着什么,以及它与普通$ dir变量之间的区别是什么?
global ${$dir};
$this->{$dir} = new $class();
Run Code Online (Sandbox Code Playgroud)
cry*_*c ツ 40
它被称为复杂的卷曲语法.
可以通过此语法包含具有字符串表示的任何标量变量,数组元素或对象属性.只需以与字符串外部相同的方式编写表达式,然后将其包装在{和}中.由于{无法转义,因此仅当$紧跟{时,才会识别此语法.使用{\ $获取文字{$.
更多信息:
http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
Ben*_*jam 13
它取得$dir变量的值并找到具有该名称的变量.
所以如果$dir = 'foo';,那么${$dir}就是一样的$foo.
同样,如果$dir = 'foo';,则与之$this->{$dir}相同$this->foo.
http://www.php.net/manual/en/language.variables.variable.php