]> granicus.if.org Git - php/commitdiff
Remove ability to declare userland case-insensitive constants
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Jan 2019 12:36:26 +0000 (13:36 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 30 Jan 2019 08:19:02 +0000 (09:19 +0100)
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
Zend/tests/bug46304.phpt
Zend/tests/case_insensitive_constant_deprecation.phpt [deleted file]
Zend/zend_builtin_functions.c

index 1dfd9dab0d1cc8c6e2f0a922126e4705be033766..0f2b9a593cfd41f9b76fd6760f01b4761abf6f82 100644 (file)
--- 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.
 
index 98988389070f6b853b0b2d91e1b2d5e1f91053eb..f8b9a0b5251ee16439813d8d424e5983223cf68d 100644 (file)
@@ -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 (file)
index e7a92c8..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
---TEST--
-Case-insensitive constants are deprecated
---FILE--
-<?php
-
-namespace {
-    define('FOO', 42, true); // Deprecated
-    define('NS\FOO', 24, true); // Deprecated
-
-    var_dump(FOO); // Ok
-    var_dump(foo); // Deprecated
-
-    var_dump(NS\FOO); // Ok
-    var_dump(ns\FOO); // Ok
-    var_dump(ns\foo); // Deprecated
-
-    var_dump(defined('FOO')); // Ok
-    var_dump(defined('foo')); // Ok
-    var_dump(defined('NS\FOO')); // Ok
-    var_dump(defined('ns\FOO')); // Ok
-    var_dump(defined('ns\foo')); // Ok
-
-    var_dump(constant('FOO')); // Ok
-    var_dump(constant('foo')); // Deprecated
-    var_dump(constant('NS\FOO')); // Ok
-    var_dump(constant('ns\FOO')); // Ok
-    var_dump(constant('ns\foo')); // Deprecated
-}
-
-namespace NS {
-    var_dump(FOO); // Ok
-    var_dump(foo); // Deprecated
-}
-
-namespace ns {
-    var_dump(FOO); // Ok
-    var_dump(foo); // Deprecated
-}
-
-namespace Other {
-    var_dump(FOO); // Ok
-    var_dump(foo); // Deprecated
-
-    var_dump(defined('FOO')); // Ok
-    var_dump(defined('foo')); // Ok
-    var_dump(defined('NS\FOO')); // Ok
-    var_dump(defined('ns\FOO')); // Ok
-    var_dump(defined('ns\foo')); // Ok
-
-    var_dump(constant('FOO')); // Ok
-    var_dump(constant('foo')); // Deprecated
-    var_dump(constant('NS\FOO')); // Ok
-    var_dump(constant('ns\FOO')); // Ok
-    var_dump(constant('ns\foo')); // Deprecated
-
-    const C1 = FOO; // Ok
-    var_dump(C1);
-    const C2 = foo; // Deprecated
-    var_dump(C2);
-    const C3 = 1 + FOO; // Ok
-    var_dump(C3);
-    const C4 = 1 + foo; // Deprecated
-    var_dump(C4);
-}
-
-?>
---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)
index 14c8fd39f9b82bf88bfaf1c3031ad63d4b03cd35..87f54ed696d4516f715ef8d67aaa3eb37667a78f 100644 (file)
@@ -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;