Skip to content

Commit 30f16c3

Browse files
committed
Compile error on function definition conflicting with import
1 parent 5b18530 commit 30f16c3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Zend/zend_compile.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ int zend_add_ns_func_name_literal(zend_op_array *op_array, const zval *zv TSRMLS
428428

429429
ns_separator = (const char*)zend_memrchr(Z_STRVAL_P(zv), '\\', Z_STRLEN_P(zv));
430430

431-
if (ns_separator != NULL) {
431+
if (ns_separator != NULL) {
432432
ns_separator += 1;
433433
lc_len = Z_STRLEN_P(zv) - (ns_separator - Z_STRVAL_P(zv));
434434
lc_name = zend_str_tolower_dup(ns_separator, lc_len);
@@ -1701,6 +1701,7 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
17011701
} else {
17021702
zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
17031703
zval key;
1704+
zval **ns_name;
17041705

17051706
if (CG(current_namespace)) {
17061707
/* Prefix function name with current namespace name */
@@ -1716,6 +1717,19 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
17161717
lcname = zend_str_tolower_dup(name, name_len);
17171718
}
17181719

1720+
/* Function name must not conflict with import names */
1721+
if (CG(current_import_function) &&
1722+
zend_hash_find(CG(current_import_function), lcname, Z_STRLEN(function_name->u.constant)+1, (void**)&ns_name) == SUCCESS) {
1723+
1724+
char *tmp = zend_str_tolower_dup(Z_STRVAL_PP(ns_name), Z_STRLEN_PP(ns_name));
1725+
1726+
if (Z_STRLEN_PP(ns_name) != Z_STRLEN(function_name->u.constant) ||
1727+
memcmp(tmp, lcname, Z_STRLEN(function_name->u.constant))) {
1728+
zend_error(E_COMPILE_ERROR, "Cannot declare function %s because the name is already in use", Z_STRVAL(function_name->u.constant));
1729+
}
1730+
efree(tmp);
1731+
}
1732+
17191733
opline->opcode = ZEND_DECLARE_FUNCTION;
17201734
opline->op1_type = IS_CONST;
17211735
build_runtime_defined_function_key(&key, lcname, name_len TSRMLS_CC);

0 commit comments

Comments
 (0)