Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

PHP reflection of standard class value returns null

Using PHP 7.2.12, I hit a snag with code reflection PHP reflecting the standard class. I can demonstrate this with the snippet below.

The reflector correctly gets the property name (id)

Why does $id_property->getValue() return NULL? I would have expected 99.

$a = new \stdClass();
$a->id = 99;
$a_reflector = new \ReflectionObject($a);
$id_property = $a_reflector->getProperties()[0];
echo $id_property->getName(); //id
var_dump($id_property->getValue());

Comments