I always get unexpected T_PAAMAYIM_NEKUDOTAYIM
tried this also
$bar = "User";
$foo = new $bar;
$foo::$value;
the whole reason im trying to do this is because i dont have late static binding
get static prop from a string get_class('User')::$value
Moderator: General Moderators
-
peanutbutter
- Forum Newbie
- Posts: 1
- Joined: Tue Mar 16, 2010 6:54 am
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: get static prop from a string get_class('User')::$value
Obviously what you're doing won't work, but you haven't really shown enough code for anyone to tell what you're trying to do.
If you've already instantiated $foo, then:
If static, then this will work in PHP 5.3 I think:
Your stuck will eval() before 5.3:
If you've already instantiated $foo, then:
Code: Select all
echo $foo->value;Code: Select all
echo $foo::$$value;Code: Select all
eval("echo $foo::$value;");mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: get static prop from a string get_class('User')::$value
Code: Select all
function getStaticValue($class, $var) {
$clz = new ReflectionClass($class);
return $clz->getStaticPropertyValue($var);
}
var_dump(getStaticValue('User', 'value'));