开发者

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

开发者 https://www.devze.com 2022-12-21 04:59 出处:网络
What does t开发者_高级运维he brakets mean and where to read more return $container->{$resource};

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

精彩评论

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