.. _reflectionclass::getconstant()-for-a-non-existent-constant-is-deprecated,: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists -------------------------------------------------------------------------------------------------------------------------------------------- .. meta:: :description: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists: ``ReflectionClass::getConstant()`` returns ``false`` both when the requested constant does not exist and when the constant's actual value is ``false``, 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: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists :og:description: ``ReflectionClass::getConstant()`` returns ``false`` both when the requested constant does not exist and when the constant's actual value is ``false``, so the return value alone cannot tell the two cases apart :og:url: https://php-errors.readthedocs.io/en/latest/messages/reflectionclass%3A%3Agetconstant%28%29-for-a-non-existent-constant-is-deprecated%2C.html :og:locale: en :twitter:card: summary_large_image :twitter:site: @exakat :twitter:title: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists :twitter:description: ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists: ``ReflectionClass::getConstant()`` returns ``false`` both when the requested constant does not exist and when the constant's actual value is ``false``, 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 ___________ ``ReflectionClass::getConstant()`` returns ``false`` both when the requested constant does not exist and when the constant's actual value is ``false``, so the return value alone cannot tell the two cases apart. Calling it for a constant that does not exist is now deprecated in favour of an explicit existence check. Example _______ .. code-block:: php getConstant('BAR'); var_dump($value); ?> Literal Examples **************** + ReflectionClass::getConstant() for a non-existent constant is deprecated, use ReflectionClass::hasConstant() to check if the constant exists Solutions _________ + Call ``ReflectionClass::hasConstant()`` first, and only call ``getConstant()`` once existence is confirmed. Related Error Messages ______________________ + :ref:`reflectionproperty::getdefaultvalue()-for-a-property-without-a-default-value-is-deprecated,` See Also ________ + `ReflectionClass::getConstant `_ + `ReflectionClass::hasConstant `_ Changed Behavior ________________ This error may appear following an evolution in behavior, in previous versions. See `ReflectionClass::getConstant `_.