When generating an object this way AND executing a method, PHP gives an error.
class A {
static public function b() {
$o = new get_called_class(); // works
$class = get_called_class();
$o = new $class; // works
$o = (new $class)->method(); // works
$o = (new get_called_class())->method(); // doesn't work
// error message: Class '...\get_called_class' not found
$o = (new (get_called_class()))->method(); // doesn't work
// error message: syntax error, unexpected '('
}
}
Why does the last lines fail?
How to write it in one line?
;and undefined classget_called_class