/** * Convert class constants to array * @return array * @param $class object|string * @param $prefix string **/ function constants($class, $prefix = '') { $ref = new ReflectionClass($class); return $this->extract($ref->getconstants(), $prefix); }
/** * Convert class constants to array * @return array * @param $prefix string **/ protected function constants($prefix) { $ref = new ReflectionClass($this); $out = array(); foreach (preg_grep('/^' . $prefix . '/', array_keys($ref->getconstants())) as $val) { $out[$key = substr($val, strlen($prefix))] = constant('self::' . $prefix . $key); } unset($ref); return $out; }
/** * Convert class constants to array * @return array * @param $class object|string * @param $prefix string **/ function constants($class, $prefix = '') { $ref = new ReflectionClass($class); $out = array(); foreach (preg_grep('/^' . $prefix . '/', array_keys($ref->getconstants())) as $val) { $out[$key = substr($val, strlen($prefix))] = constant((is_object($class) ? get_class($class) : $class) . '::' . $prefix . $key); } unset($ref); return $out; }