Skip to content

Commit f3fdf57

Browse files
committed
Intern alias old_name early
This is likely going to end up interned lateron at some point when the new_name is referenced somewhere. However, it may be that there are some uses that do not get interned before that. In this case we will intern a string that already have zval users, without updating the refcounted flag on those zvals. In particular this can happen with something like [Foo::class], where Foo is an imported symbol. The string it resolves to won't get interned right away, but may be interned later. use Foo as Bar; $x = [Bar::class]; var_dump(Bar::X); debug_zval_dump($x); // Will show negative refcount class Foo { const X = 1; } However, this doesn't really fix the root cause, there are probably other situations where something similar can occur.
1 parent 9b43e29 commit f3fdf57

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Zend/zend_compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6619,6 +6619,7 @@ void zend_compile_use(zend_ast *ast) /* {{{ */
66196619
}
66206620

66216621
zend_string_addref(old_name);
6622+
old_name = zend_new_interned_string(old_name);
66226623
if (!zend_hash_add_ptr(current_import, lookup_name, old_name)) {
66236624
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
66246625
"is already in use", zend_get_use_type_str(type), ZSTR_VAL(old_name), ZSTR_VAL(new_name));

0 commit comments

Comments
 (0)