Declaring A Class Constant Named namespace Is Deprecated
namespace is a reserved word in PHP, but a historical lexer exception allowed it to be used as the name of a class, interface, trait or enum constant, as well as a static property. Until PHP 8.6, declaring such a constant produced no warning. In PHP 8.6, declaring a constant called namespace emits a deprecation notice, reserving the word for a possible future ::namespace pseudo-constant, analogous to the existing ::class.
PHP code
<?php
class Foo {
const NAMESPACE = 'bar';
}
echo Foo::NAMESPACE, "\n";
?>
Before
bar
After
PHP Deprecated: Declaring class constant called 'namespace' is deprecated in /codes/constantNamespaceInClassDeprecated.php on line 4
Deprecated: Declaring class constant called 'namespace' is deprecated in /codes/constantNamespaceInClassDeprecated.php on line 4
bar
PHP version change
This behavior was deprecated in 8.6.
This behavior changed in .