Chris@14: getProperties() does not return private properties from ancestor classes. Chris@14: * Chris@14: * @author muratyaman@gmail.com Chris@14: * @see http://php.net/manual/en/reflectionclass.getproperties.php Chris@14: * Chris@14: * @param ReflectionClass $ref Chris@14: * Chris@14: * @return ReflectionProperty[] Chris@14: */ Chris@14: public static function getProperties(ReflectionClass $ref) Chris@14: { Chris@14: $props = $ref->getProperties(); Chris@14: $propsArr = array(); Chris@14: Chris@14: foreach ($props as $prop) { Chris@14: $propertyName = $prop->getName(); Chris@14: $propsArr[$propertyName] = $prop; Chris@14: } Chris@14: Chris@14: if ($parentClass = $ref->getParentClass()) { Chris@14: $parentPropsArr = self::getProperties($parentClass); Chris@14: foreach ($propsArr as $key => $property) { Chris@14: $parentPropsArr[$key] = $property; Chris@14: } Chris@14: Chris@14: return $parentPropsArr; Chris@14: } Chris@14: Chris@14: return $propsArr; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Retrieves property by name from object and all its ancestors. Chris@14: * Chris@14: * @param object|string $object Chris@14: * @param string $name Chris@14: * Chris@14: * @throws PropertyException Chris@14: * @throws ReflectionException Chris@14: * Chris@14: * @return ReflectionProperty Chris@14: */ Chris@14: public static function getProperty($object, $name) Chris@14: { Chris@14: $reflection = is_object($object) ? new ReflectionObject($object) : new ReflectionClass($object); Chris@14: Chris@14: if ($reflection->hasProperty($name)) { Chris@14: return $reflection->getProperty($name); Chris@14: } Chris@14: Chris@14: if ($parentClass = $reflection->getParentClass()) { Chris@14: return self::getProperty($parentClass->getName(), $name); Chris@14: } Chris@14: Chris@14: throw new PropertyException( Chris@14: sprintf( Chris@14: 'The class "%s" doesn\'t have a property with the given name: "%s".', Chris@14: is_object($object) ? get_class($object) : $object, Chris@14: $name Chris@14: ) Chris@14: ); Chris@14: } Chris@14: }