Skip to content

Commit 3c1e8e4

Browse files
[RFC] Deprecate ReflectionProperty::getDefaultValue() without default
https://wiki.php.net/rfc/deprecations_php_8_5
1 parent 2b5d978 commit 3c1e8e4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6509,11 +6509,25 @@ ZEND_METHOD(ReflectionProperty, getDefaultValue)
65096509
prop_info = ref->prop;
65106510

65116511
if (prop_info == NULL) {
6512-
return; // throw exception?
6512+
// Dynamic property
6513+
zend_error(
6514+
E_DEPRECATED,
6515+
"ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, "
6516+
"use ReflectionProperty::hasDefaultValue() to check if the default value exists"
6517+
);
6518+
return;
65136519
}
65146520

65156521
prop = property_get_default(prop_info);
65166522
if (!prop || Z_ISUNDEF_P(prop)) {
6523+
zend_error(
6524+
E_DEPRECATED,
6525+
"ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, "
6526+
"use ReflectionProperty::hasDefaultValue() to check if the default value exists"
6527+
);
6528+
if (UNEXPECTED(EG(exception))) {
6529+
RETURN_THROWS();
6530+
}
65176531
return;
65186532
}
65196533

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)