Skip to content

Commit 115c5ec

Browse files
committed
Compile error on const definition conflicting with import
1 parent 85d4cfb commit 115c5ec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Zend/zend_compile.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7251,6 +7251,7 @@ void zend_do_use_const(znode *ns_name, znode *new_name, int is_global TSRMLS_DC)
72517251
void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
72527252
{
72537253
zend_op *opline;
7254+
zval **ns_name;
72547255

72557256
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
72567257
zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants");
@@ -7271,6 +7272,19 @@ void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
72717272
*name = tmp;
72727273
}
72737274

7275+
/* Constant name must not conflict with import names */
7276+
if (CG(current_import_const) &&
7277+
zend_hash_find(CG(current_import_const), Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant)+1, (void**)&ns_name) == SUCCESS) {
7278+
7279+
char *tmp = zend_str_tolower_dup(Z_STRVAL_PP(ns_name), Z_STRLEN_PP(ns_name));
7280+
7281+
if (Z_STRLEN_PP(ns_name) != Z_STRLEN(name->u.constant) ||
7282+
memcmp(tmp, Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant))) {
7283+
zend_error(E_COMPILE_ERROR, "Cannot declare const %s because the name is already in use", Z_STRVAL(name->u.constant));
7284+
}
7285+
efree(tmp);
7286+
}
7287+
72747288
opline = get_next_op(CG(active_op_array) TSRMLS_CC);
72757289
opline->opcode = ZEND_DECLARE_CONST;
72767290
SET_UNUSED(opline->result);

0 commit comments

Comments
 (0)