如何从单个表达式中的动态对象检索静态属性?

After swapping some of my non-static vars to static vars, I ended up with some expressions similar to the one here. This throws a syntax error, but I can't figure out why.

Class Bar  {
    public static $name = "bar";
}

Class Foo {
    public function getParent(){
        $this->parentClass = new Bar();
        return $this;
    }
}

$foo = (new Foo())->getParent();
echo ($foo->parentClass)::$name; //this line is throwing a syntax error

//output:
PHP Parse error:  syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)

If I assign the object to a variable, then it doesn't throw the error:

$class = $foo->parentClass;
echo $class::$name;
//outputs "bar";

I could imagine possibly running into some unintended order of operations issues, but can't figure out why it's a syntax error, and I'm wondering if there is a way to do this in a single one line expression. (Since this issue was caused by a mass find/replace, it would be nice to keep it in one line)

It's kinda ugly, but if you really need a one-liner:

echo get_class_vars(get_class($foo->parentClass))["name"];

Inspired by this answer

DEMO

In fact this is only possible as of PHP 7.0. The changed behaviour is not well documentated. I think it's more of a bugfix than a new feature.

However the closest solution to a "one-liner" (working in 5.6) seems to be this one:

$bar = (new Foo())->getParent()->parentClass;
echo $bar::$name; 

Maybe that is not what you tried to achieve. The important thing is that the static class is only accessable by putting it into a single variable first.

I recommend a migration to PHP7 urgently.