mirror of
https://github.com/php/php-src.git
synced 2025-08-17 14:38:49 +02:00

Dynamic properties are generally referred to as "dynamic" properties, while non-dynamic properties are not commonly referred to as "default" properties. Thus, the existing method `ReflectionProperty::isDefault()` has a non obvious name; while an alias could be added for `isNotDynamic()`, a new `isDynamic()` method seems cleaner. The new method returns the opposite of `isDefault()`; dynamic properties are not present on the class by default, and properties present by default are not added dynamically. Closes GH-15754
69 lines
1.5 KiB
PHP
69 lines
1.5 KiB
PHP
--TEST--
|
|
Test ReflectionProperty::isDynamic() usage.
|
|
--FILE--
|
|
<?php
|
|
|
|
function reflectProperty($classOrObj, $property, $className = null) {
|
|
$className ??= $classOrObj;
|
|
$propInfo = new ReflectionProperty($classOrObj, $property);
|
|
echo "**********************************\n";
|
|
echo "Reflecting on property $className::$property\n\n";
|
|
echo "isDynamic():\n";
|
|
var_dump($propInfo->isDynamic());
|
|
echo "\n**********************************\n";
|
|
}
|
|
|
|
#[AllowDynamicProperties]
|
|
class TestClass {
|
|
public $pub;
|
|
static public $stat = "static property";
|
|
protected $prot = 4;
|
|
private $priv = "keepOut";
|
|
}
|
|
|
|
reflectProperty("TestClass", "pub");
|
|
reflectProperty("TestClass", "stat");
|
|
reflectProperty("TestClass", "prot");
|
|
reflectProperty("TestClass", "priv");
|
|
|
|
$obj = new TestClass();
|
|
$obj->dyn = 'dynamic';
|
|
reflectProperty($obj, "dyn", "TestClass");
|
|
|
|
?>
|
|
--EXPECT--
|
|
**********************************
|
|
Reflecting on property TestClass::pub
|
|
|
|
isDynamic():
|
|
bool(false)
|
|
|
|
**********************************
|
|
**********************************
|
|
Reflecting on property TestClass::stat
|
|
|
|
isDynamic():
|
|
bool(false)
|
|
|
|
**********************************
|
|
**********************************
|
|
Reflecting on property TestClass::prot
|
|
|
|
isDynamic():
|
|
bool(false)
|
|
|
|
**********************************
|
|
**********************************
|
|
Reflecting on property TestClass::priv
|
|
|
|
isDynamic():
|
|
bool(false)
|
|
|
|
**********************************
|
|
**********************************
|
|
Reflecting on property TestClass::dyn
|
|
|
|
isDynamic():
|
|
bool(true)
|
|
|
|
**********************************
|