Skip to content

Commit 57a88b2

Browse files
[RFC] Deprecate ReflectionProperty::getDefaultValue() without default (#19457)
https://wiki.php.net/rfc/deprecations_php_8_5
1 parent ffdc104 commit 57a88b2

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Zend/tests/property_hooks/cpp.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ var_dump($r->hasDefaultValue());
2424
var_dump($r->getDefaultValue());
2525

2626
?>
27-
--EXPECT--
27+
--EXPECTF--
2828
Pre-test
2929
Setting
3030
Constructor
3131
Getting
3232
Setting
3333
bool(false)
34+
35+
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
3436
NULL

ext/reflection/php_reflection.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6514,11 +6514,22 @@ ZEND_METHOD(ReflectionProperty, getDefaultValue)
65146514
prop_info = ref->prop;
65156515

65166516
if (prop_info == NULL) {
6517-
return; // throw exception?
6517+
// Dynamic property
6518+
zend_error(
6519+
E_DEPRECATED,
6520+
"ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, "
6521+
"use ReflectionProperty::hasDefaultValue() to check if the default value exists"
6522+
);
6523+
return;
65186524
}
65196525

65206526
prop = property_get_default(prop_info);
65216527
if (!prop || Z_ISUNDEF_P(prop)) {
6528+
zend_error(
6529+
E_DEPRECATED,
6530+
"ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, "
6531+
"use ReflectionProperty::hasDefaultValue() to check if the default value exists"
6532+
);
65226533
return;
65236534
}
65246535

ext/reflection/tests/ReflectionProperty_getDefaultValue.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ $property = new ReflectionProperty($test, 'dynamic');
6060
var_dump($property->getDefaultValue());
6161

6262
?>
63-
--EXPECT--
63+
--EXPECTF--
6464
NULL
6565
string(3) "baz"
6666
NULL
6767
int(1234)
68+
69+
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
6870
NULL
6971
int(1234)
72+
73+
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
7074
NULL
7175
NULL
7276
int(4)
7377
int(42)
78+
79+
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
7480
NULL

0 commit comments

Comments
 (0)