This works perfectly well due to PHP's variable variable functions/nightmares/godsends.
http://php.net/manual/en/language.variables.variable.php
From the docs on it (much more articulated than I could do):
Class properties may also be accessed using variable property names. The variable property name will be resolved within the scope from which the call is made. For instance, if you have an expression such as $foo->$bar, then the local scope will be examined for $bar and its value will be used as the name of the property of $foo. This is also true if $bar is an array access.
Curly braces may also be used, to clearly delimit the property name. They are most useful when accessing values within a property that contains an array, when the property name is made of mulitple parts, or when the property name contains characters that are not otherwise valid (e.g. from json_decode() or SimpleXML).
In this case, it seems that even though the object $a cannot be converted to a string through an echo $a; statement, the code is manipulating it to test when creating the new class - assuming it is due to it being an instance of class test already.
I wouldn't recommend this sort of use of variable variables though, much too confusing and non intuitive?
Okay, I did some more digging around and experimenting. It looks like it is simply shorthand for the clone function in 5.3:
<?php
class test
{
public $inc=0;
public function __construct()
{
$this->inc++;
}
function aaa() {echo $this->inc."<br>";}
}
$a = new test();
$a->aaa();
$b = new $a();
$b->aaa();
$a->inc=5;
$a->aaa();
$c = new $a();
$c->aaa();
$d= clone $b;
$d->aaa();
?>
Output:
1
1
5
1
1
So, the values aren't copied, but the constructor is used as normal.
$aclass that was introduced in PHP 5.3