Skip to content

Commit 5ad6571

Browse files
committed
Allow aliasing namespaces containing reserved class names
This reverts commit b9f7123. Fixes GH-11152 Closes GH-11153
1 parent de9b3f6 commit 5ad6571

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.7
44

5+
- Core:
6+
. Fixed bug GH-11152 (Unable to alias namespaces containing reserved class
7+
names). (ilutov)
8+
59
- Opcache:
610
. Fixed bug GH-11134 (Incorrect match default branch optimization). (ilutov)
711

Zend/tests/gh11152.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-11152: Allow aliasing namespaces containing reserved class names
3+
--FILE--
4+
<?php
5+
6+
namespace string;
7+
8+
use string as StringAlias;
9+
10+
class C {}
11+
12+
function test(StringAlias\C $o) {
13+
var_dump($o::class);
14+
}
15+
16+
test(new C());
17+
18+
?>
19+
--EXPECT--
20+
string(8) "string\C"

Zend/tests/use_statement/aliasing_builtin_types.phpt

Lines changed: 0 additions & 10 deletions
This file was deleted.

Zend/zend_compile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8124,12 +8124,6 @@ static void zend_compile_use(zend_ast *ast) /* {{{ */
81248124
zend_string *old_name = zend_ast_get_str(old_name_ast);
81258125
zend_string *new_name, *lookup_name;
81268126

8127-
/* Check that we are not attempting to alias a built-in type */
8128-
if (type == ZEND_SYMBOL_CLASS && zend_is_reserved_class_name(old_name)) {
8129-
zend_error_noreturn(E_COMPILE_ERROR,
8130-
"Cannot alias '%s' as it is a built-in type", ZSTR_VAL(old_name));
8131-
}
8132-
81338127
if (new_name_ast) {
81348128
new_name = zend_string_copy(zend_ast_get_str(new_name_ast));
81358129
} else {

0 commit comments

Comments
 (0)