From 57a88b216c7057aae7beb9e6857a1a85acf2028e Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Tue, 12 Aug 2025 05:50:27 -0700 Subject: [PATCH] [RFC] Deprecate ReflectionProperty::getDefaultValue() without default (#19457) https://wiki.php.net/rfc/deprecations_php_8_5 --- Zend/tests/property_hooks/cpp.phpt | 4 +++- ext/reflection/php_reflection.c | 13 ++++++++++++- .../tests/ReflectionProperty_getDefaultValue.phpt | 8 +++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Zend/tests/property_hooks/cpp.phpt b/Zend/tests/property_hooks/cpp.phpt index 082c182467b..1f893d853b8 100644 --- a/Zend/tests/property_hooks/cpp.phpt +++ b/Zend/tests/property_hooks/cpp.phpt @@ -24,11 +24,13 @@ var_dump($r->hasDefaultValue()); var_dump($r->getDefaultValue()); ?> ---EXPECT-- +--EXPECTF-- Pre-test Setting Constructor Getting Setting bool(false) + +Deprecated: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists in %s on line %d NULL diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 956ee472e53..b5ca21d500a 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -6514,11 +6514,22 @@ ZEND_METHOD(ReflectionProperty, getDefaultValue) prop_info = ref->prop; if (prop_info == NULL) { - return; // throw exception? + // Dynamic property + zend_error( + E_DEPRECATED, + "ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, " + "use ReflectionProperty::hasDefaultValue() to check if the default value exists" + ); + return; } prop = property_get_default(prop_info); if (!prop || Z_ISUNDEF_P(prop)) { + zend_error( + E_DEPRECATED, + "ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, " + "use ReflectionProperty::hasDefaultValue() to check if the default value exists" + ); return; } diff --git a/ext/reflection/tests/ReflectionProperty_getDefaultValue.phpt b/ext/reflection/tests/ReflectionProperty_getDefaultValue.phpt index 423edfe9faf..d74e1f4bfe6 100644 --- a/ext/reflection/tests/ReflectionProperty_getDefaultValue.phpt +++ b/ext/reflection/tests/ReflectionProperty_getDefaultValue.phpt @@ -60,15 +60,21 @@ $property = new ReflectionProperty($test, 'dynamic'); var_dump($property->getDefaultValue()); ?> ---EXPECT-- +--EXPECTF-- NULL string(3) "baz" NULL int(1234) + +Deprecated: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists in %s on line %d NULL int(1234) + +Deprecated: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists in %s on line %d NULL NULL int(4) int(42) + +Deprecated: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists in %s on line %d NULL