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)