Bug #78319 [Opn->Csd]: get_class_vars/ReflectionClass::getDefaultProperties don't show typed propertie
| From: | nikic@php.net | Date: | Wed, 24 Jul 2019 08:53:24 +0000 |
| Subject: | Bug #78319 [Opn->Csd]: get_class_vars/ReflectionClass::getDefaultProperties don't show typed propertie | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221915@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
Updated by: nikic@php.net
Reported by: nicolas dot grekas+php at gmail dot com
Summary: get_class_vars/ReflectionClass::getDefaultProperties
don't show typed propertie
-Status: Open
+Status: Closed
Type: Bug
Package: Reflection related
PHP Version: 7.4.0alpha3
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
The get_class_vars() part is fixed in https://github.com/php/php-src/commit/a49d53baa2ad2fb6a951360f0083a883e7631370,
the getDefaultProperties() part is "won't fix", so closing here.
Previous Comments:
------------------------------------------------------------------------
[2019-07-23 10:47:48] nikic@php.net
I've opened https://github.com/php/php-src/pull/4463 for
get_class_vars(). I agree that having them with a null value is better than not having them.
I don't think we should include them in getDefaultProperties() though. As far as I know
that's the only reflection API that actually provides default values -- if we change it, I
don't think there will even be a way to distinguish a null default / an uninitialized default
from reflection. As getProperties() does include them and getDefaultProperties() is specifically
about defaults (which don't exist here), I think we should leave that one alone.
------------------------------------------------------------------------
[2019-07-23 08:27:21] nicolas dot grekas+php at gmail dot com
Another reason why this is important: get_class_vars() takes the scope into account so that now
it's much harder to get props for the current scope.
------------------------------------------------------------------------
[2019-07-22 15:24:04] nicolas dot grekas+php at gmail dot com
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.
------------------------------------------------------------------------
[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