Bug #79236 [Opn->Nab]: Uninitialized properties are hidden from get_object_vars

From: Date: Thu, 06 Feb 2020 19:00:04 +0000
Subject: Bug #79236 [Opn->Nab]: Uninitialized properties are hidden from get_object_vars
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225396@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79236&edit=1 ID: 79236 Updated by: requinix@php.net Reported by: raincomplain at outlook dot com Summary: Uninitialized properties are hidden from get_object_vars -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related Operating System: Irrelevant PHP Version: 7.4.2 Block user comment: N Private report: N New Comment: This is working as intended. get_object_vars() does not show the property because it's uninitialized: it's not appropriate to list it as num1 => null because the value is not null - which isn't even a valid value for it. It's omitted unless/until there is a value assigned. get_class_vars() shows the property because it is defined on the class. There is a distinct utility to showing that the property is there, even if its default value is uninitialized. This all is very much like how unset()ing properties works. https://3v4l.org/lAIEX Previous Comments: ------------------------------------------------------------------------ [2020-02-06 16:09:21] raincomplain at outlook dot com Description: ------------ Little bit of hesitation on this one but I had to report it since no answers were found on SO https://stackoverflow.com/q/60087384/5999372 So uninitialized properties are hidden from get_object_vars but exposed to get_class_vars like as Null Test script: --------------- class A { public int $num1; public $num2; } var_dump(get_object_vars(new A)); var_dump(get_class_vars('A')); Expected result: ---------------- array(1) { ["num1"]=> NULL ["num2"]=> NULL } array(2) { ["num1"]=> NULL ["num2"]=> NULL } Here to be honest I'm not sure whether get_class_vars should not show num1 and treat it as Null or whether get_object_class should show num1 either, but I assume they should output the same result especially since the properties are public. Actual result: -------------- array(1) { ["num2"]=> NULL } array(2) { ["num1"]=> NULL ["num2"]=> NULL } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79236&edit=1

« previous php.bugs (#225396) next »