-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
Description
The following code:
<?php declare(strict_types=1);
class Bug {
private static $foo;
private static int $bar;
}
$rc = new ReflectionClass(Bug::class);
var_dump($rc->getStaticPropertyValue('foo'));
var_dump($v = $rc->getStaticPropertyValue('bar'));
echo "bar = {$v}\n";Resulted in this output:
NULL
UNKNOWN:0
Warning: Undefined variable $v in ... on line 11
bar =
But I expected this output instead:
Well TBH, I'm not sure... If the goal is to be consistent with ReflectionProperty::getValue(), then:
NULL
Fatal error: Uncaught Error: Typed static property Bug::$bar must not be accessed before initialization in ...
Otherwise, then:
NULL
NULL
Looking at the implementation, the code calls zend_std_get_static_property(ce, name, BP_VAR_IS); which silences exceptions, but also completely bypasses the typed property initialization check.
So it looks like:
- if the behaviour of
ReflectionProperty::getValue()is desired, then the method should useBP_VAR_Rinstead ofBP_VAR_IS(or just usezend_read_static_property_exwithsilent=false) - otherwise the conditional in
zend_std_get_static_propertyshould be fixed to return a null pointer regardless of theBP_VAR_*mode.
PHP Version
PHP 8.3-dev
Operating System
irrelevant