Bug #78319 [Com]: get_class_vars/ReflectionClass::getDefaultProperties don't show typed propertie

From: Date: Mon, 22 Jul 2019 15:24:04 +0000
Subject: Bug #78319 [Com]: get_class_vars/ReflectionClass::getDefaultProperties don't show typed propertie
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221894@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78319&edit=1 ID: 78319 Comment by: nicolas dot grekas+php at gmail dot com Reported by: nicolas dot grekas+php at gmail dot com Summary: get_class_vars/ReflectionClass::getDefaultProperties don't show typed propertie Status: Open Type: Bug Package: Reflection related PHP Version: 7.4.0alpha3 Block user comment: N Private report: N New Comment: In any case, existing scripts will need to be adapted. The cases that were affected in my situation were only looking at keys, without caring about the default values. Not returning typed properties is equally wrong to be, so the best approximation is "null" to me, because it allows not breaking scripts like mines. Others that look for values will need to be adapted in whatever the behavior anyway. Previous Comments: ------------------------------------------------------------------------ [2019-07-22 15:07:47] nikic@php.net Not sure about this one. I can see how not returning them can be a problem, but just returning null also seems wrong, because it's not the actual default value. ------------------------------------------------------------------------ [2019-07-22 07:53:07] nicolas dot grekas+php at gmail dot com Description: ------------ get_class_vars()/ReflectionClass::getDefaultProperties() don't show typed properties. I get they aren't yet initialized, but we could report them as "null" to no break scripts that look only for their names. Test script: --------------- class Php74 { public $p1 = 123; public \stdClass $p2; public function __construct() { $this->p2 = new \stdClass(); } } print_r(get_class_vars('Php74')); $r = new \ReflectionClass('Php74'); print_r($r->getDefaultProperties()); print_r($r->getProperties()); Expected result: ---------------- Array ( [p1] => 123 [p2] => ) Array ( [p1] => 123 [p2] => ) Array ( [0] => ReflectionProperty Object ( [name] => p1 [class] => Php74 ) [1] => ReflectionProperty Object ( [name] => p2 [class] => Php74 ) ) Actual result: -------------- Array ( [p1] => 123 ) Array ( [p1] => 123 ) Array ( [0] => ReflectionProperty Object ( [name] => p1 [class] => Php74 ) [1] => ReflectionProperty Object ( [name] => p2 [class] => Php74 ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78319&edit=1

« previous php.bugs (#221894) next »