Skip to content

Commit c6e3ea8

Browse files
krakjoenikic
authored andcommitted
handle attributes nicely
1 parent 4aece83 commit c6e3ea8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Zend/tests/first_class_callable_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class Foo {
99
new Foo(...);
1010
?>
1111
--EXPECTF--
12-
Fatal error: cannot create Closure for new expression in %s on line 6
12+
Fatal error: Cannot create Closure for new expression in %s on line 6
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
First Class Callable Attribute Error
3+
--FILE--
4+
<?php
5+
#[Attribute(...)]
6+
class Foo {
7+
8+
}
9+
?>
10+
--EXPECTF--
11+
Fatal error: Cannot create Closure as attribute argument in %s on line 3

Zend/zend_compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3697,7 +3697,7 @@ void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *
36973697
opline->extended_value = 0;
36983698

36993699
if (opline->opcode == ZEND_NEW) {
3700-
zend_error_noreturn(E_COMPILE_ERROR, "cannot create Closure for new expression");
3700+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for new expression");
37013701
}
37023702

37033703
if (opline->opcode == ZEND_INIT_FCALL) {
@@ -6397,6 +6397,13 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3
63976397
ZEND_ASSERT(group->child[i]->kind == ZEND_AST_ATTRIBUTE);
63986398

63996399
zend_ast *el = group->child[i];
6400+
6401+
if (el->child[1] &&
6402+
el->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) {
6403+
zend_error_noreturn(E_COMPILE_ERROR,
6404+
"Cannot create Closure as attribute argument");
6405+
}
6406+
64006407
zend_string *name = zend_resolve_class_name_ast(el->child[0]);
64016408
zend_ast_list *args = el->child[1] ? zend_ast_get_list(el->child[1]) : NULL;
64026409

0 commit comments

Comments
 (0)