Skip to content

Commit ed202b2

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Don't throw CompileError after parsing
2 parents a2f7c9d + 7e860ea commit ed202b2

File tree

2 files changed

+4
-73
lines changed

2 files changed

+4
-73
lines changed

Zend/tests/use_statement/aliasing_builtin_types.phpt

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,8 @@ Aliasing built-in types
33
--FILE--
44
<?php
55

6-
/* Taken from zend_compile.c reserved_class_names[] struct */
7-
/* array and list are also added as they are language constructs */
8-
$types = [
9-
"bool",
10-
"false",
11-
"float",
12-
"int",
13-
"null",
14-
"parent",
15-
"self",
16-
"static",
17-
"string",
18-
"true",
19-
"void",
20-
"never",
21-
"iterable",
22-
"object",
23-
"mixed",
24-
"array",
25-
"list",
26-
];
27-
28-
foreach ($types as $type) {
29-
try {
30-
eval("use $type as A;");
31-
} catch (\Throwable $e) {
32-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
33-
}
34-
try {
35-
eval("use $type as A; function foo$type(A \$v): A { return \$v; }");
36-
} catch (\Throwable $e) {
37-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
38-
}
39-
}
6+
use bool as A;
407

418
?>
42-
DONE
43-
--EXPECT--
44-
CompileError: Cannot alias 'bool' as it is a built-in type
45-
CompileError: Cannot alias 'bool' as it is a built-in type
46-
CompileError: Cannot alias 'false' as it is a built-in type
47-
CompileError: Cannot alias 'false' as it is a built-in type
48-
CompileError: Cannot alias 'float' as it is a built-in type
49-
CompileError: Cannot alias 'float' as it is a built-in type
50-
CompileError: Cannot alias 'int' as it is a built-in type
51-
CompileError: Cannot alias 'int' as it is a built-in type
52-
CompileError: Cannot alias 'null' as it is a built-in type
53-
CompileError: Cannot alias 'null' as it is a built-in type
54-
CompileError: Cannot alias 'parent' as it is a built-in type
55-
CompileError: Cannot alias 'parent' as it is a built-in type
56-
CompileError: Cannot alias 'self' as it is a built-in type
57-
CompileError: Cannot alias 'self' as it is a built-in type
58-
ParseError: syntax error, unexpected token "static"
59-
ParseError: syntax error, unexpected token "static"
60-
CompileError: Cannot alias 'string' as it is a built-in type
61-
CompileError: Cannot alias 'string' as it is a built-in type
62-
CompileError: Cannot alias 'true' as it is a built-in type
63-
CompileError: Cannot alias 'true' as it is a built-in type
64-
CompileError: Cannot alias 'void' as it is a built-in type
65-
CompileError: Cannot alias 'void' as it is a built-in type
66-
CompileError: Cannot alias 'never' as it is a built-in type
67-
CompileError: Cannot alias 'never' as it is a built-in type
68-
CompileError: Cannot alias 'iterable' as it is a built-in type
69-
CompileError: Cannot alias 'iterable' as it is a built-in type
70-
CompileError: Cannot alias 'object' as it is a built-in type
71-
CompileError: Cannot alias 'object' as it is a built-in type
72-
CompileError: Cannot alias 'mixed' as it is a built-in type
73-
CompileError: Cannot alias 'mixed' as it is a built-in type
74-
ParseError: syntax error, unexpected token "array"
75-
ParseError: syntax error, unexpected token "array"
76-
ParseError: syntax error, unexpected token "list"
77-
ParseError: syntax error, unexpected token "list"
78-
DONE
9+
--EXPECTF--
10+
Fatal error: Cannot alias 'bool' as it is a built-in type in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8084,9 +8084,8 @@ static void zend_compile_use(zend_ast *ast) /* {{{ */
80848084

80858085
/* Check that we are not attempting to alias a built-in type */
80868086
if (type == ZEND_SYMBOL_CLASS && zend_is_reserved_class_name(old_name)) {
8087-
zend_throw_exception_ex(zend_ce_compile_error, 0,
8087+
zend_error_noreturn(E_COMPILE_ERROR,
80888088
"Cannot alias '%s' as it is a built-in type", ZSTR_VAL(old_name));
8089-
return;
80908089
}
80918090

80928091
if (new_name_ast) {

0 commit comments

Comments
 (0)