Take the 2-minute tour ×

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


instead of

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted
class Foo {
    const BAR = 'bar';
    public static $baz = 'baz';

$foo = 'Foo';
echo $foo::BAR;
echo $foo::$baz;

This requires PHP 5.3+ though.

share|improve this answer
+1 more concise :) –  SiGanteng Apr 23 '12 at 6:14
add comment

You can use ReflectionClass

class A {
        public static $x = 5;

$class = new ReflectionClass('A');
echo $class->getStaticPropertyValue('x');


share|improve this answer
add comment

Your Answer


