Skip to content
Draft
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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.6.0beta1

- Core:
. Deprecated "namespace" as a class constant name. (NickSdot)

- GMP:
. Added optional $definitely_prime output parameter to gmp_prevprime().
(Weilin Du)
Expand Down
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,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.
Expand Down
67 changes: 67 additions & 0 deletions Zend/tests/deprecate_namespace_class_constant.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--TEST--
Using "namespace" as a class constant name is deprecated
--FILE--
<?php

define('namespace', 'global constant value');

class Foo {
const NAMESPACE = 'class constant value';
}

interface Bar {
const Namespace = 'interface constant value';
}

enum Baz {
const nAmEsPaCe = 'enum constant value';
}

trait YooTrait {
const namespace = 'trait constant value';
}

class Sup {
use YooTrait;
}

enum Yoo: string {
case namespace = 'enum case value';
}

class Can {
public static $namespace = 'property value';

public static function namespace() {
return 'method value';
}
}

echo Foo::NAMESPACE, PHP_EOL;
echo Bar::Namespace, PHP_EOL;
echo Baz::nAmEsPaCe, PHP_EOL;
echo Yoo::namespace->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
3 changes: 2 additions & 1 deletion Zend/tests/grammar/semi_reserved_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -4861,6 +4861,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))) {
Expand Down
Loading