Commit e0693e9c3df for php.net
commit e0693e9c3dffe80f3d3ad72eac820ff8df5b5c69
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date: Sun Jul 19 10:11:11 2026 -0700
Reflection: add regression tests for lazy initialization errors
Add tests for the four error cases in
`reflection_property_check_lazy_compatible()`, as triggered by both
`ReflectionProperty::setRawValueWithoutLazyInitialization()` and
`ReflectionProperty::skipLazyInitialization()`. While some of these errors are
covered by existing tests, having all of the errors in one place will make it
easier to see the changes when the error messages are improved.
diff --git a/ext/reflection/tests/ReflectionProperty_lazy_initialization_errors.phpt b/ext/reflection/tests/ReflectionProperty_lazy_initialization_errors.phpt
new file mode 100644
index 00000000000..bb7bb56c0fa
--- /dev/null
+++ b/ext/reflection/tests/ReflectionProperty_lazy_initialization_errors.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test ReflectionProperty::setRawValueWithoutLazyInitialization() and skipLazyInitialization() errors
+--FILE--
+<?php
+
+#[AllowDynamicProperties]
+class Demo {
+ public static $myStatic;
+
+ public bool $myVirtual {
+ get => true;
+ }
+}
+
+function test(object $obj, string $propertyName) {
+ $r = new ReflectionProperty($obj, $propertyName);
+ try {
+ $r->setRawValueWithoutLazyInitialization($obj, true);
+ } catch (ReflectionException $e) {
+ echo $e->getMessage() . "\n";
+ }
+ try {
+ $r->skipLazyInitialization($obj);
+ } catch (ReflectionException $e) {
+ echo $e->getMessage() . "\n\n";
+ }
+}
+
+$obj = new Demo();
+test($obj, 'myStatic');
+test($obj, 'myVirtual');
+
+$obj->myDynamic = true;
+test($obj, 'myDynamic');
+
+$obj = new ReflectionClass(Demo::class);
+test($obj, 'name');
+
+?>
+--EXPECT--
+Can not use setRawValueWithoutLazyInitialization on static property Demo::$myStatic
+Can not use skipLazyInitialization on static property Demo::$myStatic
+
+Can not use setRawValueWithoutLazyInitialization on virtual property Demo::$myVirtual
+Can not use skipLazyInitialization on virtual property Demo::$myVirtual
+
+Can not use setRawValueWithoutLazyInitialization on dynamic property Demo::$myDynamic
+Can not use skipLazyInitialization on dynamic property Demo::$myDynamic
+
+Can not use setRawValueWithoutLazyInitialization on internal class ReflectionClass
+Can not use skipLazyInitialization on internal class ReflectionClass