3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PHPFI { public $a = 'A PROPERTY'; protected $b = 'B PROPERTY'; private $c = 'C PROPERTY'; } $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" // }

preferences:
63.75 ms | 404 KiB | 5 Q