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
Post a Comment