3v4l.org

run code in 200+ php & hhvm versions
<?php class PHPFI { public $a = 'A PROPERTY'; protected $b = 'B PROPERTY'; private $c = 'C PROPERTY'; public function __construct() { unset($this->a, $this->b, $this->c); } } $phpfi = new PHPFI(); var_dump((array) $phpfi); // array(3) { // ["a"]=> // string(10) "A PROPERTY" // ["*b"]=> // string(10) "B PROPERTY" // ["PHPFIc"]=> // string(10) "C PROPERTY" // } $reflect = new ReflectionClass($phpfi); $reflectProps = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE); $props = []; foreach ($reflectProps as $prop) { switch (true) { case $prop->isProtected(): $prefix = '*'; break; case $prop->isPrivate(): $prefix = $prop->getDeclaringClass()->getName(); break; default: $prefix = ''; break; } $prop->setAccessible(true); $props[$prefix . $prop->getName()] = $prop->getValue($phpfi); } var_dump($props); // array(3) { // ["a"]=> // string(10) "A PROPERTY" // ["*b"]=> // string(10) "B PROPERTY" // ["PHPFIc"]=> // string(10) "C PROPERTY" // }
based on Dh3PO
Output for 7.1.25 - 7.3.5
array(0) { } Notice: Undefined property: PHPFI::$a in /in/BtDs5 on line 44 Notice: Undefined property: PHPFI::$b in /in/BtDs5 on line 44 Notice: Undefined property: PHPFI::$c in /in/BtDs5 on line 44 array(3) { ["a"]=> NULL ["*b"]=> NULL ["PHPFIc"]=> NULL }