Reputation: 3441
I have a call lets assume its called A
public class A{
...
}
how can I access the members of this class while I have the name of the class
what I need is something like this
{"A"}::x=5;
instead of
A::x=5;
Upvotes: 0
Views: 31
Reputation: 522109
class Foo {
const BAR = 'bar';
public static $baz = 'baz';
}
$foo = 'Foo';
echo $foo::BAR;
echo $foo::$baz;
This requires PHP 5.3+ though.
Upvotes: 5
Reputation: 60526
You can use ReflectionClass
class A {
public static $x = 5;
}
$class = new ReflectionClass('A');
echo $class->getStaticPropertyValue('x');
http://php.net/manual/en/class.reflectionclass.php
Upvotes: 4