views:

54

answers:

1

Is there a way to do get all the constants in a php class. Tried get_class_vars( get_called_class() )

    class Status
{        
    const PUBLISHED = "published";
    const DRAFT = "draft";

    public static function get_types()
    {
        return array(self::PUBLISHED, self::DRAFT);
    }
}

Thanks

+7  A: 

This

 $reflector = new ReflectionClass('Status');
 var_dump($reflector->getConstants());
Wrikken
+1 This would be it since I can't find any built-in procedural PHP functions for getting class constants, which is a bit of a shame.
BoltClock
Probably because there is little need for it. The OP might want to do a meta-configuration by setting `types` as `all constants this class has`, which in most cases, and in my granted limited opinion, are probably better served with either inheritance or a static array variable with the types (leaving room for constants with other meanings / use).
Wrikken