gerrardywhz
New Member
Is it possible to access a sub-property of an object dynamically? I managed it to access the properties of an object, but not the properties of a sub-object.Here is an example of the things I want to do:\[code\]class SubTest{ public $age; public function __construct($age) { $this->age = $age; }}class Test{ public $name; public $sub; public function __construct($name, $age) { $this->name = $name; $this->sub = new SubTest($age); }}$test = new Test("Mike", 43);// NOTE works fine$access_property1 = "name";echo $test->$access_property1;// NOTE doesn't work, returns null$access_property2 = "sub->age";echo $test->$access_property2;\[/code\]Thanks in advance!