Skip to content

[RFC] Deprecate ReflectionProperty::getDefaultValue() without default #19457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Zend/tests/property_hooks/cpp.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6509,11 +6509,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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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