开发者

what does " return $container->{$resource};" mean

What does t开发者_高级运维he brakets mean and where to read more

return $container->{$resource};


The brackets are to make use of variable variables. It makes it easier to distinguish between:

// gets the value of the "resource" member from the container object
$container->resource;

and

// gets the value of the "foo" member from the container object
$resource = 'foo';
$container->$resource;

You can read more here: http://php.net/manual/en/language.variables.variable.php


Two possibilities:

  1. variable variable.

    $resource = "score"; // set the name dynamically

    return $container->{$resource}; // same as return $container->score;

  2. typo / beginner mistake

The programmer meant to type:

return $container->resource;  // returns resource public member variable
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜