Files
php-src/ext/reflection/tests/ReflectionClass_getStaticProperties.phpt
Daniel Scherzer 08c039c87a ReflectionClass::getStaticProperties(): optimize array initialization
For classes with no static properties, avoid allocating an array that will be
empty. Includes a regression test for the function since it was previously
untested, to confirm that even when a class declares no static properties of
its own, inherited static properties are still returned.
2026-07-07 10:33:41 -07:00

58 lines
925 B
PHP

--TEST--
ReflectionClass::getStaticProperties()
--FILE--
<?php
class Base {
public static $pub;
private static $priv;
public static mixed $pubTyped;
private static mixed $privTyped;
}
class Child extends Base {}
$base = new ReflectionClass(Base::class);
$child = new ReflectionClass(Child::class);
echo "Start:\n";
var_dump($base->getStaticProperties());
var_dump($child->getStaticProperties());
echo "\nTyped properties initialized\n:";
Base::$pubTyped = true;
$base->setStaticPropertyValue('privTyped', true);
var_dump($base->getStaticProperties());
var_dump($child->getStaticProperties());
?>
--EXPECT--
Start:
array(2) {
["pub"]=>
NULL
["priv"]=>
NULL
}
array(1) {
["pub"]=>
NULL
}
Typed properties initialized
:array(4) {
["pub"]=>
NULL
["priv"]=>
NULL
["pubTyped"]=>
bool(true)
["privTyped"]=>
bool(true)
}
array(2) {
["pub"]=>
NULL
["pubTyped"]=>
bool(true)
}