[php-src] master: Reflection: add regression tests for lazy initialization errors

From: Date: Mon, 27 Jul 2026 17:37:45 +0000
Subject: [php-src] master: Reflection: add regression tests for lazy initialization errors
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-140237@lists.php.net to get a copy of this message
Author: Daniel Scherzer (DanielEScherzer) Date: 2026-07-27T10:36:50-07:00 Commit: https://github.com/php/php-src/commit/e0693e9c3dffe80f3d3ad72eac820ff8df5b5c69 Raw diff: https://github.com/php/php-src/commit/e0693e9c3dffe80f3d3ad72eac820ff8df5b5c69.diff 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. Changed paths: A ext/reflection/tests/ReflectionProperty_lazy_initialization_errors.phpt Diff: 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 000000000000..bb7bb56c0fa9 --- /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

« previous php.cvs (#140237) next »