Commit 29f351d3554 for php.net

commit 29f351d35542744c96837ae44e996785cc646b7e
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date:   Tue Aug 11 14:40:47 2026 -0700

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

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

diff --git a/UPGRADING b/UPGRADING
index f82aad3f8b3..34e3f62c521 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -476,6 +476,11 @@ PHP 8.6 UPGRADE NOTES
   . The mysqli_get_charset() function is now deprecated.
     RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_mysqli_get_charset

+- Reflection:
+  . 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
+
 - SPL:
   . The spl_classes() function is now deprecated, use
     ReflectionExtension::getClassNames() instead.
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 0b1c458db08..90fa559794c 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -5919,6 +5919,15 @@ ZEND_METHOD(ReflectionProperty, setValue)
 			Z_PARAM_ZVAL(value)
 		ZEND_PARSE_PARAMETERS_END();

+		if (!instanceof_function(object->ce, 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();
+			}
+		}
+
 		const zend_class_entry *old_scope = EG(fake_scope);
 		EG(fake_scope) = intern->ce;
 		object->handlers->write_property(object, ref->unmangled_name, value, ref->cache_slot);
diff --git a/ext/reflection/tests/ReflectionProperty_setValue_error.phpt b/ext/reflection/tests/ReflectionProperty_setValue_error.phpt
index 287a03679e6..25dd9adae2a 100644
--- a/ext/reflection/tests/ReflectionProperty_setValue_error.phpt
+++ b/ext/reflection/tests/ReflectionProperty_setValue_error.phpt
@@ -30,11 +30,13 @@ class AnotherClass {
 var_dump($propInfo->setValue($instanceWithNoProperties, "NewValue"));
 var_dump($instanceWithNoProperties->pub2);
 ?>
---EXPECT--
+--EXPECTF--
 Protected property:
 string(8) "NewValue"


 Instance without property:
+
+Deprecated: Calling ReflectionProperty::setValue() with a given object that is not an instance of the class this property was declared in is deprecated in %s on line %d
 NULL
 string(8) "NewValue"