diff --git a/NEWS b/NEWS index b99bdc51e87c..40a56ed20fba 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ PHP NEWS ?? ??? ????, PHP 8.6.0beta1 - Core: + . Deprecated "namespace" as a class constant name. (NickSdot) . Changed run-tests.php to run test subprocesses without a shell where possible. (NickSdot) . Fixed GH-23083 (SEGV build_trace_args in zend_exceptions.c with diff --git a/UPGRADING b/UPGRADING index ba4bf182911f..49c7a3f576cf 100644 --- a/UPGRADING +++ b/UPGRADING @@ -433,6 +433,7 @@ PHP 8.6 UPGRADE NOTES ======================================== - Core: + . Using "namespace" as a class constant name is deprecated. . Specifying a return type of array|null / ?array for __debugInfo() is now deprecated. Specify array instead. . Returning values from __construct() and __destruct() is now deprecated. diff --git a/Zend/tests/deprecate_namespace_class_constant.phpt b/Zend/tests/deprecate_namespace_class_constant.phpt new file mode 100644 index 000000000000..c44ebbc258da --- /dev/null +++ b/Zend/tests/deprecate_namespace_class_constant.phpt @@ -0,0 +1,67 @@ +--TEST-- +Using "namespace" as a class constant name is deprecated +--FILE-- +value, PHP_EOL; +echo Sup::namespace, PHP_EOL; +echo Can::$namespace, PHP_EOL; +echo Can::namespace(), PHP_EOL; +echo constant('namespace'), PHP_EOL; + +?> +--EXPECTF-- +Deprecated: Declaring class constant called 'namespace' is deprecated in %s on line %d + +Deprecated: Declaring interface constant called 'namespace' is deprecated in %s on line %d + +Deprecated: Declaring enum constant called 'namespace' is deprecated in %s on line %d + +Deprecated: Declaring trait constant called 'namespace' is deprecated in %s on line %d + +Deprecated: Declaring enum constant called 'namespace' is deprecated in %s on line %d +class constant value +interface constant value +enum constant value +enum case value +trait constant value +property value +method value +global constant value diff --git a/Zend/tests/grammar/semi_reserved_005.phpt b/Zend/tests/grammar/semi_reserved_005.phpt index 4a9a19e11812..06c428eacbc3 100644 --- a/Zend/tests/grammar/semi_reserved_005.phpt +++ b/Zend/tests/grammar/semi_reserved_005.phpt @@ -160,7 +160,8 @@ echo Obj::__NAMESPACE__, PHP_EOL; echo "\nDone\n"; ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Declaring class constant called 'namespace' is deprecated in %s on line %d empty callable trait diff --git a/Zend/zend_API.c b/Zend/zend_API.c index de3570c5e848..e0ed9a97b54e 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -4833,6 +4833,9 @@ ZEND_API zend_class_constant *zend_declare_typed_class_constant(zend_class_entry if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_CLASS))) { zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR, "A class constant must not be called 'class'; it is reserved for class name fetching"); + } else if (zend_string_equals_literal_ci(name, "namespace")) { + zend_error(E_DEPRECATED, "Declaring %s constant called 'namespace' is deprecated", + zend_get_object_type(ce)); } if (Z_TYPE_P(value) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(value))) {