3v4l.org

run code in 300+ PHP versions simultaneously
<?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" // }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(0) { } Warning: Undefined property: PHPFI::$a in /in/BtDs5 on line 44 Warning: Undefined property: PHPFI::$b in /in/BtDs5 on line 44 Warning: Undefined property: PHPFI::$c in /in/BtDs5 on line 44 array(3) { ["a"]=> NULL ["*b"]=> NULL ["PHPFIc"]=> NULL }
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
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 }
Output for 7.3.32 - 7.3.33
array(0) { } array(3) { ["a"]=> NULL ["*b"]=> NULL ["PHPFIc"]=> NULL }

preferences:
169.9 ms | 401 KiB | 184 Q