Commit 1b5de53960a for php.net

commit 1b5de53960ab99b288bae2d92748a68a95bff99a
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date:   Tue Aug 11 15:00:18 2026 -0700

    [RFC] Deprecate `ReflectionProperty::setRawValue()` with wrong types

    https://wiki.php.net/rfc/deprecations_php_8_6

diff --git a/UPGRADING b/UPGRADING
index 34e3f62c521..bfc23acb0fa 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -480,6 +480,9 @@ PHP 8.6 UPGRADE NOTES
   . Calling ReflectionProperty::setValue() with an object that is not an
     instance of the class on which the property was declared is now deprecated.
     RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_reflectionpropertysetvalue_and_reflectionpropertysetrawvalue_with_wrong_types
+  . Calling ReflectionProperty::setRawValue() with an object that is not an
+    instance of the class on which the property was declared is now deprecated.
+    RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_reflectionpropertysetvalue_and_reflectionpropertysetrawvalue_with_wrong_types

 - SPL:
   . The spl_classes() function is now deprecated, use
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 90fa559794c..426ac625a9f 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -6055,6 +6055,15 @@ ZEND_METHOD(ReflectionProperty, setRawValue)
 		Z_PARAM_ZVAL(value)
 	} ZEND_PARSE_PARAMETERS_END();

+	if (!instanceof_function(Z_OBJCE_P(object), intern->ce)) {
+		zend_string *method_name = get_active_function_or_method_name();
+		zend_error(E_DEPRECATED, "Calling %pS() with a given object that is not an instance of the class this property was declared in is deprecated", method_name);
+		zend_string_release(method_name);
+		if (UNEXPECTED(EG(exception))) {
+			RETURN_THROWS();
+		}
+	}
+
 	zend_reflection_property_set_raw_value(ref->prop, ref->unmangled_name,
 			ref->cache_slot, intern->ce, Z_OBJ_P(object), value);
 }
diff --git a/ext/reflection/tests/ReflectionProperty_setRawValue_error.phpt b/ext/reflection/tests/ReflectionProperty_setRawValue_error.phpt
new file mode 100644
index 00000000000..0044e447b76
--- /dev/null
+++ b/ext/reflection/tests/ReflectionProperty_setRawValue_error.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Test ReflectionProperty::setRawValue() error cases.
+--FILE--
+<?php
+
+class Example {
+    public mixed $nonHooked;
+
+    public mixed $hooked {
+        set(mixed $value) {
+            throw new Exception("hook should not be called");
+            $this->hooked = "Not virtual";
+        }
+    }
+}
+
+#[AllowDynamicProperties]
+class AnotherClass {
+}
+
+$hookedProp = new ReflectionProperty(Example::class, 'hooked');
+$nonHookedProp = new ReflectionProperty(Example::class, 'nonHooked');
+
+$instance = new Example();
+$hookedProp->setRawValue($instance, "value1");
+$nonHookedProp->setRawValue($instance, "value2");
+var_dump($instance);
+
+$other = new AnotherClass();
+$hookedProp->setRawValue($other, "value1");
+$nonHookedProp->setRawValue($other, "value2");
+var_dump($other);
+?>
+--EXPECTF--
+object(Example)#%d (2) {
+  ["nonHooked"]=>
+  string(6) "value2"
+  ["hooked"]=>
+  string(6) "value1"
+}
+
+Deprecated: Calling ReflectionProperty::setRawValue() with a given object that is not an instance of the class this property was declared in is deprecated in %s on line %d
+
+Deprecated: Calling ReflectionProperty::setRawValue() with a given object that is not an instance of the class this property was declared in is deprecated in %s on line %d
+object(AnotherClass)#%d (2) {
+  ["hooked"]=>
+  string(6) "value1"
+  ["nonHooked"]=>
+  string(6) "value2"
+}