Bug #78954 [Opn->Nab]: get_object_vars not returning typed empty properties

From: Date: Thu, 12 Dec 2019 13:52:42 +0000
Subject: Bug #78954 [Opn->Nab]: get_object_vars not returning typed empty properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224248@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78954&edit=1 ID: 78954 Updated by: nikic@php.net Reported by: thomas dot wiringa at gmail dot com Summary: get_object_vars not returning typed empty properties -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Arch Linux / Linux 5.4.2 PHP Version: 7.4.0 Block user comment: N Private report: N New Comment: get_object_vars() does not return null, because those values are not null. These properties have not been initialized -- essentially they do not exist. If you wish to get all the properties that were *declared* in the class, regardless of whether they have been initialized or unset, you can use ReflectionObject. Previous Comments: ------------------------------------------------------------------------ [2019-12-12 13:33:21] thomas dot wiringa at gmail dot com Description: ------------ When using typed properties such as public string $foo; or public ?string $foo; get_object_vars does not return [ 'foo' => NULL ] if this property was never set. However, pre-7.4 it would return the property in the array if it was defined as public $foo; but never set/changed. Test script: --------------- https://3v4l.org/eg6o0 Expected result: ---------------- string(20) "bar exists in $vars" string(28) "foobar exists in $vars" string(20) "foo exists in $vars" Actual result: -------------- string(19) "bar exists in $vars" Warning: assert(): assert(array_key_exists('foobar', $vars)) failed in /in/eg6o0 on line 12 string(30) "foobar does not exist in $vars" Warning: assert(): assert(array_key_exists('foo', $vars)) failed in /in/eg6o0 on line 13 string(27) "foo does not exist in $vars" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78954&edit=1

« previous php.bugs (#224248) next »