括号是什么意思以及在何处阅读更多
return $container->{$resource};
答案 0 :(得分:4)
括号是利用变量变量。它可以更容易区分:
// gets the value of the "resource" member from the container object
$container->resource;
和
// gets the value of the "foo" member from the container object
$resource = 'foo';
$container->$resource;
您可以在此处阅读更多内容:http://php.net/manual/en/language.variables.variable.php
答案 1 :(得分:3)
两种可能性:
$ resource =“得分”; //动态设置名称
返回$ container-> {$ resource}; //与return $ container->得分相同;
错字/初学者错误
程序员打算输入:
return $container->resource; // returns resource public member variable