3v4l.org

run code in 200+ php & hhvm versions
<?php class Foo { public $foo; } class Bar extends Foo { public $bar; } $barClassReflection = new ReflectionClass(Bar::class); $properties = $barClassReflection->getProperties(); var_dump($properties); foreach ($properties as $property) { var_dump($property->getName()); var_dump($property->class); var_dump($property->getDeclaringClass()->getName()); var_dump($property->class === $property->getDeclaringClass()->getName()); }
based on Qg9jI
Output for 7.0.33 - 7.3.0
array(2) { [0]=> object(ReflectionProperty)#2 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "Bar" } [1]=> object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "foo" ["class"]=> string(3) "Foo" } } string(3) "bar" string(3) "Bar" string(3) "Bar" bool(true) string(3) "foo" string(3) "Foo" string(3) "Foo" bool(true)
Output for 5.6.38
array(2) { [0]=> &object(ReflectionProperty)#2 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "Bar" } [1]=> &object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "foo" ["class"]=> string(3) "Foo" } } string(3) "bar" string(3) "Bar" string(3) "Bar" bool(true) string(3) "foo" string(3) "Foo" string(3) "Foo" bool(true)