Skip to content

Commit 3d39479

Browse files
committed
Remove support for case-insensitive constants
The only remaining case-insensitive constants are null, true and false, which are handled explicitly. In the future we may convert them from constants to reserved keywords.
1 parent 3d478e5 commit 3d39479

File tree

8 files changed

+129
-253
lines changed

8 files changed

+129
-253
lines changed

Zend/tests/008.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ NULL
2929

3030
Warning: define() expects at least 2 parameters, 1 given in %s on line %d
3131
NULL
32-
bool(true)
32+
33+
Notice: Constant TRUE already defined in %s on line %d
34+
bool(false)
3335

3436
Warning: define() expects parameter 3 to be bool, array given in %s on line %d
3537
NULL

Zend/zend_builtin_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ ZEND_FUNCTION(defined)
854854
Z_PARAM_STR(name)
855855
ZEND_PARSE_PARAMETERS_END();
856856

857-
if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT | ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK)) {
857+
if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)) {
858858
RETURN_TRUE;
859859
} else {
860860
RETURN_FALSE;

Zend/zend_compile.c

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,6 @@ static int zend_add_const_name_literal(zend_string *name, zend_bool unqualified)
585585
zend_str_tolower(ZSTR_VAL(tmp_name), ns_len);
586586
zend_add_literal_string(&tmp_name);
587587

588-
/* lowercased namespace name & lowercased constant name */
589-
tmp_name = zend_string_tolower(name);
590-
zend_add_literal_string(&tmp_name);
591-
592588
if (!unqualified) {
593589
return ret;
594590
}
@@ -600,11 +596,6 @@ static int zend_add_const_name_literal(zend_string *name, zend_bool unqualified)
600596
tmp_name = zend_string_init(after_ns, after_ns_len, 0);
601597
zend_add_literal_string(&tmp_name);
602598

603-
/* lowercased unqualified constant name */
604-
tmp_name = zend_string_alloc(after_ns_len, 0);
605-
zend_str_tolower_copy(ZSTR_VAL(tmp_name), after_ns, after_ns_len);
606-
zend_add_literal_string(&tmp_name);
607-
608599
return ret;
609600
}
610601
/* }}} */
@@ -1213,22 +1204,9 @@ ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char
12131204
}
12141205
/* }}} */
12151206

1216-
static zend_constant *zend_lookup_reserved_const(const char *name, size_t len) /* {{{ */
1217-
{
1218-
zend_constant *c = zend_hash_find_ptr_lc(EG(zend_constants), name, len);
1219-
if (c && !(ZEND_CONSTANT_FLAGS(c) & CONST_CS) && (ZEND_CONSTANT_FLAGS(c) & CONST_CT_SUBST)) {
1220-
return c;
1221-
}
1222-
return NULL;
1223-
}
1224-
/* }}} */
1225-
12261207
static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool is_fully_qualified) /* {{{ */
12271208
{
1228-
zend_constant *c;
1229-
1230-
/* Substitute case-sensitive (or lowercase) constants */
1231-
c = zend_hash_find_ptr(EG(zend_constants), name);
1209+
zend_constant *c = zend_hash_find_ptr(EG(zend_constants), name);
12321210
if (c && (
12331211
((ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)
12341212
&& !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION)
@@ -1243,19 +1221,19 @@ static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool i
12431221
/* Substitute true, false and null (including unqualified usage in namespaces) */
12441222
const char *lookup_name = ZSTR_VAL(name);
12451223
size_t lookup_len = ZSTR_LEN(name);
1224+
zval *val;
12461225

12471226
if (!is_fully_qualified) {
12481227
zend_get_unqualified_name(name, &lookup_name, &lookup_len);
12491228
}
12501229

1251-
c = zend_lookup_reserved_const(lookup_name, lookup_len);
1252-
if (c) {
1253-
ZVAL_COPY_OR_DUP(zv, &c->value);
1230+
if ((val = zend_get_special_const(lookup_name, lookup_len))) {
1231+
ZVAL_COPY_VALUE(zv, val);
12541232
return 1;
12551233
}
1256-
}
12571234

1258-
return 0;
1235+
return 0;
1236+
}
12591237
}
12601238
/* }}} */
12611239

@@ -3249,13 +3227,6 @@ int zend_compile_func_defined(znode *result, zend_ast_list *args) /* {{{ */
32493227
LITERAL_STR(opline->op1, name);
32503228
opline->extended_value = zend_alloc_cache_slot();
32513229

3252-
/* Lowercase constant name in a separate literal */
3253-
{
3254-
zval c;
3255-
zend_string *lcname = zend_string_tolower(name);
3256-
ZVAL_NEW_STR(&c, lcname);
3257-
zend_add_literal(&c);
3258-
}
32593230
return SUCCESS;
32603231
}
32613232
/* }}} */
@@ -6538,7 +6509,7 @@ void zend_compile_const_decl(zend_ast *ast) /* {{{ */
65386509
value_node.op_type = IS_CONST;
65396510
zend_const_expr_to_zval(value_zv, value_ast);
65406511

6541-
if (zend_lookup_reserved_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
6512+
if (zend_get_special_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
65426513
zend_error_noreturn(E_COMPILE_ERROR,
65436514
"Cannot redeclare constant '%s'", ZSTR_VAL(unqualified_name));
65446515
}

0 commit comments

Comments
 (0)