Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Zend/tests/bug42859.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Foo;
class Ex {}

use Blah\Exception;
use Blah\Ex;
var_dump(new Ex);
?>
--EXPECTF--
Fatal error: Cannot use Blah\Ex as Ex because the name is already in use in %sbug42859.php on line 6
object(Foo\Ex)#%d (0) {
}
2 changes: 1 addition & 1 deletion Zend/tests/ns_030.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ use A\B as Foo;

new Foo();
--EXPECTF--
Fatal error: Cannot use A\B as Foo because the name is already in use in %sns_030.php on line 5
Fatal error: Class 'A\B' not found in %s on line %d
6 changes: 2 additions & 4 deletions Zend/tests/use_const/define_imported_before.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ namespace {
const bar = 42;

use const foo\bar;
}

namespace {
echo "Done";
echo bar;
}

?>
--EXPECTF--
Fatal error: Cannot use const foo\bar as bar because the name is already in use in %s on line %d
Fatal error: Undefined constant 'foo\bar' in %s on line %d
6 changes: 2 additions & 4 deletions Zend/tests/use_function/define_imported_before.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ namespace {
function bar() {}

use function foo\bar;
}

namespace {
echo "Done";
bar();
}

?>
--EXPECTF--
Fatal error: Cannot use function foo\bar as bar because the name is already in use in %s on line %d
Fatal error: Call to undefined function foo\bar() in %s on line %d
56 changes: 0 additions & 56 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4924,17 +4924,6 @@ static char *zend_get_use_type_str(uint32_t type) /* {{{ */
}
/* }}} */

static void zend_check_already_in_use(uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name) /* {{{ */
{
if (zend_string_equals_ci(old_name, check_name)) {
return;
}

zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
"is already in use", zend_get_use_type_str(type), old_name->val, new_name->val);
}
/* }}} */

void zend_compile_use(zend_ast *ast) /* {{{ */
{
zend_ast_list *list = zend_ast_get_list(ast);
Expand Down Expand Up @@ -4987,51 +4976,6 @@ void zend_compile_use(zend_ast *ast) /* {{{ */
"is a special class name", old_name->val, new_name->val, new_name->val);
}

if (current_ns) {
zend_string *ns_name = zend_string_alloc(current_ns->len + 1 + new_name->len, 0);
zend_str_tolower_copy(ns_name->val, current_ns->val, current_ns->len);
ns_name->val[current_ns->len] = '\\';
memcpy(ns_name->val + current_ns->len + 1, lookup_name->val, lookup_name->len);

if (zend_hash_exists(CG(class_table), ns_name)) {
zend_check_already_in_use(type, old_name, new_name, ns_name);
}

zend_string_free(ns_name);
} else {
switch (type) {
case T_CLASS:
{
zend_class_entry *ce = zend_hash_find_ptr(CG(class_table), lookup_name);
if (ce && ce->type == ZEND_USER_CLASS
&& ce->info.user.filename == CG(compiled_filename)
) {
zend_check_already_in_use(type, old_name, new_name, lookup_name);
}
break;
}
case T_FUNCTION:
{
zend_function *fn = zend_hash_find_ptr(CG(function_table), lookup_name);
if (fn && fn->type == ZEND_USER_FUNCTION
&& fn->op_array.filename == CG(compiled_filename)
) {
zend_check_already_in_use(type, old_name, new_name, lookup_name);
}
break;
}
case T_CONST:
{
zend_string *filename = zend_hash_find_ptr(&CG(const_filenames), lookup_name);
if (filename && filename == CG(compiled_filename)) {
zend_check_already_in_use(type, old_name, new_name, lookup_name);
}
break;
}
EMPTY_SWITCH_DEFAULT_CASE()
}
}

zend_string_addref(old_name);
if (!zend_hash_add_ptr(current_import, lookup_name, old_name)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
Expand Down