variables - PHP 5.5: accessing a static class member of a dynamic class stored in an object -


we assume following:

class {   public static $foo = 'bar'; } class b {   public $classname = 'a'; } $b = new b(); 

is somehow (curly braces etc.) possible access $foo directly without generating "unexpected :: (t_paamayim_nekudotayim)":

$b->classname::$foo //should result in "bar" not in "unexpected :: (t_paamayim_nekudotayim)" 

i know , use following workaround:

$c = $b->classname; $c::$foo; 

but know if exists nice way access $foo directly.

you can using variables variable as

class {   public static $foo = 'bar';    public function getstatic(){       return self::$foo;   } } class b {   public $classname = 'a'; } $b = new b(); $a = new a(); echo ${$b->classname}->getstatic();//bar 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -