tags:

views:

100

answers:

2

What does the brakets mean and where to read more

return $container->{$resource};
+3  A: 

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
Yada
It's unlikely to be a typo. It would be hard to "mistype" a dollar sign and two brackets and not notice.
Ilia Jerebtsov
True. The {} is hard to mis type, but I've seen a lot of bugs where programmer type return $container->$resource;
Yada
+4  A: 

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

Ilia Jerebtsov