Hi Tech Nerds,
Here are some tips that came from the problem that I faced in CakePHP. Actually I needed to fetch all constnats of a class. Basically it uses concept of “ReflectionClass” (that is predefined in PHP). I described my function as:
1 2 3 4 5 6 7 8 9 10 11 12 13 | if (!function_exists('getClassConstants')) { /** * Get list of all constants of a class * @param string $class Path of class * @return array */ function getClassConstants($class) { $reflectionClass = new ReflectionClass($class); return $reflectionClass->getConstants(); } } |
You need to just pass the class PATH to this function as
1 | getClassConstants("\NAMESPACE_OR_PATH_OF_YOUR_CLASS"); |
This will result an associative Array.