Question: 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:

```
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;

```

Answer: 
The jQuery $.post function sends a post request to the server, which means to access the value of "result", you need to get it from the $\_POST superglobal.

Try $\_POST['result'] instead of $\_SERVER['result'].

These descriptions may help (source: <http://www.nusphere.com/php/php_superglobals.htm>):

* **$\_POST**- The $\_POST Superglobal represents data sent to the PHP
script via HTTP POST. This is
normally a form with a method of
POST.
* **$\_SERVER**- The $\_SERVER Superglobal represents data available
to a PHP script from the Web server
itself (not what you're looking for)
* **$\_REQUEST**- The $\_REQUEST Superglobal is a combination of
$\_GET, $\_POST, and $\_COOKIE (would
work, but why search GET and COOKIE
when you know the value is in POST?)
Use `$_REQUEST['result']`

> 
> [`$_SERVER`](http://php.net/manual/en/reserved.variables.server.php) is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.
> 
> 
> [`$_REQUEST`](http://www.php.net/manual/en/reserved.variables.request.php) is an associative array that by default contains the contents of `$_GET`, `$_POST` and `$_COOKIE`.
> 
> 
> 

The correct way is to use `$_POST['result']`, as suggested by others here.