From 23a5be3696f4d92e1b18fd59f3ac63c6a15ea12a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 29 Jan 2019 13:36:26 +0100 Subject: [PATCH] Remove ability to declare userland case-insensitive constants This is part of https://wiki.php.net/rfc/case_insensitive_constant_deprecation. This commit only removes the ability to declare such constants from userland. Before the functionality can be removed entirely, it's necessary to figure out the handling of true/false/null first. --- UPGRADING | 2 + Zend/tests/bug46304.phpt | 45 ------- ...case_insensitive_constant_deprecation.phpt | 127 ------------------ Zend/zend_builtin_functions.c | 18 +-- 4 files changed, 9 insertions(+), 183 deletions(-) delete mode 100644 Zend/tests/case_insensitive_constant_deprecation.phpt diff --git a/UPGRADING b/UPGRADING index 1dfd9dab0d..0f2b9a593c 100644 --- a/UPGRADING +++ b/UPGRADING @@ -26,6 +26,8 @@ PHP 8.0 UPGRADE NOTES . Removed (unset) cast. . Removed track_errors ini directive. This means that $php_errormsg is no longer available. The error_get_last() function may be used instead. + . Removed the ability to define case-insensitive constants. The third + argument to define() may no longer be true. . Removed create_function(). Anonymous functions may be used instead. . Removed each(). foreach or ArrayIterator should be used instead. diff --git a/Zend/tests/bug46304.phpt b/Zend/tests/bug46304.phpt index 9898838907..f8b9a0b525 100644 --- a/Zend/tests/bug46304.phpt +++ b/Zend/tests/bug46304.phpt @@ -6,9 +6,6 @@ Bug #46304 (defining namespaced constant using define()) define('NS1\ns2\const1','value1'); define('ns1\ns2\const2','value2'); define('ns1\NS2\coNSt3','value3'); -define('NS1\ns2\const4','value4', true); -define('ns1\ns2\const5','value5', true); -define('ns1\NS2\coNSt6','value6', true); print NS1\ns2\const1 . "\n"; print ns1\ns2\const1 . "\n"; @@ -22,29 +19,9 @@ print NS1\ns2\coNSt3 . "\n"; print ns1\ns2\coNSt3 . "\n"; print ns1\ns2\coNSt3 . "\n"; -print NS1\ns2\const4 . "\n"; -print ns1\ns2\const4 . "\n"; -print ns1\NS2\const4 . "\n"; -print ns1\ns2\coNSt4 . "\n"; - -print NS1\ns2\const5 . "\n"; -print ns1\ns2\const5 . "\n"; -print ns1\NS2\const5 . "\n"; -print ns1\ns2\coNSt5 . "\n"; - -print NS1\ns2\const6 . "\n"; -print ns1\ns2\const6 . "\n"; -print ns1\NS2\const6 . "\n"; -print ns1\ns2\coNSt6 . "\n"; - print NS1\ns2\coNSt1 . "\n"; ?> --EXPECTF-- -Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 6 - -Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 7 - -Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 8 value1 value1 value1 @@ -54,28 +31,6 @@ value2 value3 value3 value3 -value4 -value4 -value4 - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS1\ns2\const4" in %s on line 25 -value4 -value5 -value5 -value5 - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\ns2\const5" in %s on line 30 -value5 - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\NS2\coNSt6" in %s on line 32 -value6 - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\NS2\coNSt6" in %s on line 33 -value6 - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\NS2\coNSt6" in %s on line 34 -value6 -value6 Fatal error: Uncaught Error: Undefined constant 'NS1\ns2\coNSt1' in %sbug46304.php:%d Stack trace: diff --git a/Zend/tests/case_insensitive_constant_deprecation.phpt b/Zend/tests/case_insensitive_constant_deprecation.phpt deleted file mode 100644 index e7a92c8c4c..0000000000 --- a/Zend/tests/case_insensitive_constant_deprecation.phpt +++ /dev/null @@ -1,127 +0,0 @@ ---TEST-- -Case-insensitive constants are deprecated ---FILE-- - ---EXPECTF-- -Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 4 - -Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 5 -int(42) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "FOO" in %s on line 8 -int(42) -int(24) -int(24) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS\FOO" in %s on line 12 -int(24) -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) -int(42) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "FOO" in %s on line 21 -int(42) -int(24) -int(24) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS\FOO" in %s on line 24 -int(24) -int(24) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS\FOO" in %s on line 29 -int(24) -int(24) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS\FOO" in %s on line 34 -int(24) -int(42) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "FOO" in %s on line 39 -int(42) -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) -int(42) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "FOO" in %s on line 48 -int(42) -int(24) -int(24) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS\FOO" in %s on line 51 -int(24) -int(42) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "FOO" in %s on line 55 -int(42) -int(43) - -Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "FOO" in %s on line 59 -int(43) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 14c8fd39f9..87f54ed696 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -765,7 +765,6 @@ ZEND_FUNCTION(define) zend_string *name; zval *val, val_free; zend_bool non_cs = 0; - int case_sensitive = CONST_CS; zend_constant c; ZEND_PARSE_PARAMETERS_START(2, 3) @@ -775,15 +774,17 @@ ZEND_FUNCTION(define) Z_PARAM_BOOL(non_cs) ZEND_PARSE_PARAMETERS_END(); - if (non_cs) { - case_sensitive = 0; - } - if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) { zend_error(E_WARNING, "Class constants cannot be defined or redefined"); RETURN_FALSE; } + if (non_cs) { + zend_error(E_WARNING, + "define(): Declaration of case-insensitive constants is no longer supported"); + RETURN_FALSE; + } + ZVAL_UNDEF(&val_free); repeat: @@ -831,13 +832,8 @@ repeat: zval_ptr_dtor(&val_free); register_constant: - if (non_cs) { - zend_error(E_DEPRECATED, - "define(): Declaration of case-insensitive constants is deprecated"); - } - /* non persistent */ - ZEND_CONSTANT_SET_FLAGS(&c, case_sensitive, PHP_USER_CONSTANT); + ZEND_CONSTANT_SET_FLAGS(&c, CONST_CS, PHP_USER_CONSTANT); c.name = zend_string_copy(name); if (zend_register_constant(&c) == SUCCESS) { RETURN_TRUE; -- 2.50.1