get_class_vars() and typed properties

From: Date: Sun, 18 Aug 2019 09:59:20 +0000
Subject: get_class_vars() and typed properties
Groups: php.internals 
Request: Send a blank email to internals+get-106640@lists.php.net to get a copy of this message
Hi Internals, I just noticed the following behaviour: class A { public int $a; public ?int $b; public ?int $c = null; } $a = new A; var_export(get_object_vars($a)); var_export(get_class_vars('A')); Result: array ( 'c' => NULL, ) array ( 'a' => NULL, 'b' => NULL, 'c' => NULL, ) Is this discrepancy expected? IMO get_object_vars() does the right thing and does not include uninitialized properties in the result array. OTOH, get_class_vars() returns null when the property is uninitialized, which I think is confusing (especially when null is not a valid value for the property), and I feel like this does not respect the documented contract: "get_class_vars — Get the default properties of the class" when null is *not* the default value. I did not file a bug yet as I wanted to gather some feedback first. Thank you. — Benjamin

« previous php.internals (#106640) next »