Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.647.2.27.2.41.2.31 diff -u -r1.647.2.27.2.41.2.31 zend_compile.c --- Zend/zend_compile.c 13 Dec 2007 10:02:03 -0000 1.647.2.27.2.41.2.31 +++ Zend/zend_compile.c 22 Dec 2007 06:40:09 -0000 @@ -1191,6 +1191,14 @@ efree(lcname); } else { zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); + int alias_clash = 0; + zval **alias; + + /* Function name must not conflict with import names */ + if (CG(current_import) && + zend_hash_find(CG(current_import), lcname, Z_STRLEN(function_name->u.constant)+1, (void**)&alias) == SUCCESS) { + alias_clash = 1; + } if (CG(current_namespace)) { /* Prefix function name with current namespcae name */ @@ -1199,12 +1207,24 @@ tmp.u.constant = *CG(current_namespace); zval_copy_ctor(&tmp.u.constant); zend_do_build_namespace_name(&tmp, &tmp, function_name TSRMLS_CC); + function_name = &tmp; op_array.function_name = Z_STRVAL(tmp.u.constant); efree(lcname); name_len = Z_STRLEN(tmp.u.constant); lcname = zend_str_tolower_dup(Z_STRVAL(tmp.u.constant), name_len); } + if (alias_clash) { + /* Check if clashing alias actually points to a different name */ + char *tmp = zend_str_tolower_dup(Z_STRVAL_PP(alias), Z_STRLEN_PP(alias)); + + if (Z_STRLEN_PP(alias) != Z_STRLEN(function_name->u.constant) || + memcmp(tmp, lcname, Z_STRLEN(function_name->u.constant))) { + zend_error(E_COMPILE_ERROR, "Cannot declare function %s because the name is already in use", Z_STRVAL(function_name->u.constant)); + } + efree(tmp); + } + opline->opcode = ZEND_DECLARE_FUNCTION; opline->op1.op_type = IS_CONST; build_runtime_defined_function_key(&opline->op1.u.constant, lcname, name_len TSRMLS_CC); @@ -1380,23 +1400,34 @@ char *lcname; int prefix_len = 0; - if (check_namespace && CG(current_namespace)) { - /* We assume we call function from the current namespace - if it is not prefixed. */ - znode tmp; + lcname = zend_str_tolower_dup(function_name->u.constant.value.str.val, function_name->u.constant.value.str.len); - tmp.op_type = IS_CONST; - tmp.u.constant = *CG(current_namespace); - zval_copy_ctor(&tmp.u.constant); - zend_do_build_namespace_name(&tmp, &tmp, function_name TSRMLS_CC); - *function_name = tmp; + if (check_namespace && (CG(current_import) || CG(current_namespace))) { + zval **alias; - /* In run-time PHP will check for function with full name and - internal function with short name */ - prefix_len = Z_STRLEN_P(CG(current_namespace)) + 2; + if (CG(current_import) && + zend_hash_find(CG(current_import), lcname, Z_STRLEN(function_name->u.constant)+1, (void**)&alias) == SUCCESS) { + /* The given name is an import name. Substitute it. */ + zval_dtor(&function_name->u.constant); + function_name->u.constant = **alias; + zval_copy_ctor(&function_name->u.constant); + } else if (CG(current_namespace)) { + /* We assume we call function from the current namespace + if it is not prefixed and is not an import name. */ + znode tmp; + + tmp.op_type = IS_CONST; + tmp.u.constant = *CG(current_namespace); + zval_copy_ctor(&tmp.u.constant); + zend_do_build_namespace_name(&tmp, &tmp, function_name TSRMLS_CC); + *function_name = tmp; + + /* In run-time PHP will check for function with full name and + internal function with short name */ + prefix_len = Z_STRLEN_P(CG(current_namespace)) + 2; + } } - lcname = zend_str_tolower_dup(function_name->u.constant.value.str.val, function_name->u.constant.value.str.len); if (zend_hash_find(CG(function_table), lcname, function_name->u.constant.value.str.len+1, (void **) &function)==FAILURE) { zend_do_begin_dynamic_function_call(function_name, prefix_len TSRMLS_CC); efree(lcname); @@ -4825,7 +4856,8 @@ ns_name[Z_STRLEN_P(CG(current_namespace))] = ':'; ns_name[Z_STRLEN_P(CG(current_namespace))+1] = ':'; memcpy(ns_name+Z_STRLEN_P(CG(current_namespace))+2, lcname, Z_STRLEN_P(name)+1); - if (zend_hash_exists(CG(class_table), ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1)) { + if (zend_hash_exists(CG(class_table), ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1) || + zend_hash_exists(CG(function_table), ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1)) { char *tmp = zend_str_tolower_dup(Z_STRVAL_P(ns), Z_STRLEN_P(ns)); if (Z_STRLEN_P(ns) != Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name) || @@ -4835,7 +4867,8 @@ efree(tmp); } efree(ns_name); - } else if (zend_hash_exists(CG(class_table), lcname, Z_STRLEN_P(name)+1)) { + } else if (zend_hash_exists(CG(class_table), lcname, Z_STRLEN_P(name)+1) || + zend_hash_exists(CG(function_table), lcname, Z_STRLEN_P(name)+1)) { char *tmp = zend_str_tolower_dup(Z_STRVAL_P(ns), Z_STRLEN_P(ns)); if (Z_STRLEN_P(ns) != Z_STRLEN_P(name) ||