.. _reflectionproperty::getdefaultvalue()-for-a-property-without-a-default-value-is-deprecated,:
ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
.. meta::
:description:
ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists: ``ReflectionProperty::getDefaultValue()`` returns ``null`` both when the property genuinely defaults to ``null`` and when the property has no default value at all (such as an uninitialized typed property), so the return value alone cannot tell the two cases apart.
:og:image: https://php-errors.readthedocs.io/en/latest/_static/logo.png
:og:type: article
:og:title: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists
:og:description: ``ReflectionProperty::getDefaultValue()`` returns ``null`` both when the property genuinely defaults to ``null`` and when the property has no default value at all (such as an uninitialized typed property), so the return value alone cannot tell the two cases apart
:og:url: https://php-errors.readthedocs.io/en/latest/messages/reflectionproperty%3A%3Agetdefaultvalue%28%29-for-a-property-without-a-default-value-is-deprecated%2C.html
:og:locale: en
:twitter:card: summary_large_image
:twitter:site: @exakat
:twitter:title: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists
:twitter:description: ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists: ``ReflectionProperty::getDefaultValue()`` returns ``null`` both when the property genuinely defaults to ``null`` and when the property has no default value at all (such as an uninitialized typed property), so the return value alone cannot tell the two cases apart
:twitter:creator: @exakat
:twitter:image:src: https://php-errors.readthedocs.io/en/latest/_static/logo.png
.. raw:: html
Description
___________
``ReflectionProperty::getDefaultValue()`` returns ``null`` both when the property genuinely defaults to ``null`` and when the property has no default value at all (such as an uninitialized typed property), so the return value alone cannot tell the two cases apart. Calling it for a property that has no default value is now deprecated in favour of an explicit existence check.
Example
_______
.. code-block:: php
getDefaultValue());
?>
Literal Examples
****************
+ ReflectionProperty::getDefaultValue() for a property without a default value is deprecated, use ReflectionProperty::hasDefaultValue() to check if the default value exists
Solutions
_________
+ Call ``ReflectionProperty::hasDefaultValue()`` first, and only call ``getDefaultValue()`` once a default value is confirmed to exist.
Related Error Messages
______________________
+ :ref:`reflectionclass::getconstant()-for-a-non-existent-constant-is-deprecated,`
See Also
________
+ `ReflectionProperty::getDefaultValue `_
+ `ReflectionProperty::hasDefaultValue `_
Changed Behavior
________________
This error may appear following an evolution in behavior, in previous versions. See `ReflectionProperty::getDefaultValue `_.