什么是“返回$ container-> {$ resource};”意思

时间:2010-02-20 14:43:19

标签: php

括号是什么意思以及在何处阅读更多

return $container->{$resource};

2 个答案:

答案 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)

两种可能性:

  1. variable variable

    $ resource =“得分”; //动态设置名称

    返回$ container-> {$ resource}; //与return $ container->得分相同;

  2. 错字/初学者错误

  3. 程序员打算输入:

    return $container->resource;  // returns resource public member variable
    
相关问题