mirror of
https://github.com/php/php-src.git
synced 2026-10-29 02:07:35 +08:00
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.
58 lines
925 B
PHP
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)
|
|
}
|