I would use json_encode
. You will have to convert the class to an associative array first.
$constants = array("RESOURCE_TYPE_REGISTER"=>2, "RESOURCE_TYPE_INFO"=>2);
echo json_encode($constants);
You could also use reflection to convert the class to an associative array if you would prefer to use a class.
function get_class_consts($class_name)
{
$c = new ReflectionClass($class_name);
return ($c->getConstants());
}
class Constants {
const RESOURCE_TYPE_REGSITER = 2;
const RESOURCE_TYPE_INFO = 1;
}
echo json_encode(get_class_consts("Constants"));