Skip to content

Commit 23a5be3

Browse files
committed
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.
1 parent 90bb326 commit 23a5be3

File tree

4 files changed

+9
-183
lines changed

4 files changed

+9
-183
lines changed

UPGRADING

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ PHP 8.0 UPGRADE NOTES
2626
. Removed (unset) cast.
2727
. Removed track_errors ini directive. This means that $php_errormsg is no
2828
longer available. The error_get_last() function may be used instead.
29+
. Removed the ability to define case-insensitive constants. The third
30+
argument to define() may no longer be true.
2931
. Removed create_function(). Anonymous functions may be used instead.
3032
. Removed each(). foreach or ArrayIterator should be used instead.
3133

Zend/tests/bug46304.phpt

-45
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ Bug #46304 (defining namespaced constant using define())
66
define('NS1\ns2\const1','value1');
77
define('ns1\ns2\const2','value2');
88
define('ns1\NS2\coNSt3','value3');
9-
define('NS1\ns2\const4','value4', true);
10-
define('ns1\ns2\const5','value5', true);
11-
define('ns1\NS2\coNSt6','value6', true);
129

1310
print NS1\ns2\const1 . "\n";
1411
print ns1\ns2\const1 . "\n";
@@ -22,29 +19,9 @@ print NS1\ns2\coNSt3 . "\n";
2219
print ns1\ns2\coNSt3 . "\n";
2320
print ns1\ns2\coNSt3 . "\n";
2421

25-
print NS1\ns2\const4 . "\n";
26-
print ns1\ns2\const4 . "\n";
27-
print ns1\NS2\const4 . "\n";
28-
print ns1\ns2\coNSt4 . "\n";
29-
30-
print NS1\ns2\const5 . "\n";
31-
print ns1\ns2\const5 . "\n";
32-
print ns1\NS2\const5 . "\n";
33-
print ns1\ns2\coNSt5 . "\n";
34-
35-
print NS1\ns2\const6 . "\n";
36-
print ns1\ns2\const6 . "\n";
37-
print ns1\NS2\const6 . "\n";
38-
print ns1\ns2\coNSt6 . "\n";
39-
4022
print NS1\ns2\coNSt1 . "\n";
4123
?>
4224
--EXPECTF--
43-
Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 6
44-
45-
Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 7
46-
47-
Deprecated: define(): Declaration of case-insensitive constants is deprecated in %s on line 8
4825
value1
4926
value1
5027
value1
@@ -54,28 +31,6 @@ value2
5431
value3
5532
value3
5633
value3
57-
value4
58-
value4
59-
value4
60-
61-
Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "NS1\ns2\const4" in %s on line 25
62-
value4
63-
value5
64-
value5
65-
value5
66-
67-
Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\ns2\const5" in %s on line 30
68-
value5
69-
70-
Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\NS2\coNSt6" in %s on line 32
71-
value6
72-
73-
Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\NS2\coNSt6" in %s on line 33
74-
value6
75-
76-
Deprecated: Case-insensitive constants are deprecated. The correct casing for this constant is "ns1\NS2\coNSt6" in %s on line 34
77-
value6
78-
value6
7934

8035
Fatal error: Uncaught Error: Undefined constant 'NS1\ns2\coNSt1' in %sbug46304.php:%d
8136
Stack trace:

Zend/tests/case_insensitive_constant_deprecation.phpt

-127
This file was deleted.

Zend/zend_builtin_functions.c

+7-11
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ ZEND_FUNCTION(define)
765765
zend_string *name;
766766
zval *val, val_free;
767767
zend_bool non_cs = 0;
768-
int case_sensitive = CONST_CS;
769768
zend_constant c;
770769

771770
ZEND_PARSE_PARAMETERS_START(2, 3)
@@ -775,15 +774,17 @@ ZEND_FUNCTION(define)
775774
Z_PARAM_BOOL(non_cs)
776775
ZEND_PARSE_PARAMETERS_END();
777776

778-
if (non_cs) {
779-
case_sensitive = 0;
780-
}
781-
782777
if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
783778
zend_error(E_WARNING, "Class constants cannot be defined or redefined");
784779
RETURN_FALSE;
785780
}
786781

782+
if (non_cs) {
783+
zend_error(E_WARNING,
784+
"define(): Declaration of case-insensitive constants is no longer supported");
785+
RETURN_FALSE;
786+
}
787+
787788
ZVAL_UNDEF(&val_free);
788789

789790
repeat:
@@ -831,13 +832,8 @@ ZEND_FUNCTION(define)
831832
zval_ptr_dtor(&val_free);
832833

833834
register_constant:
834-
if (non_cs) {
835-
zend_error(E_DEPRECATED,
836-
"define(): Declaration of case-insensitive constants is deprecated");
837-
}
838-
839835
/* non persistent */
840-
ZEND_CONSTANT_SET_FLAGS(&c, case_sensitive, PHP_USER_CONSTANT);
836+
ZEND_CONSTANT_SET_FLAGS(&c, CONST_CS, PHP_USER_CONSTANT);
841837
c.name = zend_string_copy(name);
842838
if (zend_register_constant(&c) == SUCCESS) {
843839
RETURN_TRUE;

0 commit comments

Comments
 (0)