Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

What does the brakets mean and where to read more

return $container->{$resource};
like image 242
simple Avatar asked Dec 11 '25 07:12

simple


1 Answers

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

like image 183
Alex J Avatar answered Dec 12 '25 21:12

Alex J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!