私は小さな例を作成しようとしました。これにより、この構文が明確になることを願っています。
//A class that represents a fruit basket, a collection of fruits. Similar to $smarty, which is a collection of variables (among other things)
class FruitBasket
{
public $basket = array();
public function foo() {
}
}
//A class that represents a fruit. It has some properties, like 'name' and 'color'
class Fruit
{
public $name = null;
public $color = null;
public function __construct($fruit_name) {
$this->name = $fruit_name;
}
}
$fruits = array(); //Make an array that will hold various fruits
$fruit = new Fruit('banana'); //Create a fruit
$fruit->color = 'yellow'; //Assign a value to its 'color' property
$fruits['banana'] = $fruit; //Assign the fruit to the 'fruits' array
//Make the same steps for 2 more fruits
$fruit = new Fruit('apple');
$fruit->color = 'red';
$fruits['apple'] = $fruit;
$fruit = new Fruit('pear');
$fruit->color = 'green';
$fruits['pear'] = $fruit;
$fruit_basket = new FruitBasket(); //Create a new fruit basket
$fruit_basket->basket = $fruits; //Assign the $fruits array to its 'basket' property
echo $fruit_basket->basket['banana']->color; //prints 'yellow'