Skip to content

Commit 161b714

Browse files
committed
handle attributes nicely
1 parent c6cfd7f commit 161b714

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Diff for: Zend/tests/first_class_callable_008.phpt

+1-1
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

Diff for: Zend/tests/first_class_callable_011.phpt

+11
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

Diff for: Zend/zend_compile.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -3702,7 +3702,7 @@ void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *
37023702
opline->extended_value = 0;
37033703

37043704
if (opline->opcode == ZEND_NEW) {
3705-
zend_error_noreturn(E_COMPILE_ERROR, "cannot create Closure for new expression");
3705+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for new expression");
37063706
}
37073707

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

64046404
zend_ast *el = group->child[i];
6405+
6406+
if (el->child[1] &&
6407+
el->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) {
6408+
zend_error_noreturn(E_COMPILE_ERROR,
6409+
"Cannot create Closure as attribute argument");
6410+
}
6411+
64056412
zend_string *name = zend_resolve_class_name_ast(el->child[0]);
64066413
zend_ast_list *args = el->child[1] ? zend_ast_get_list(el->child[1]) : NULL;
64076414

0 commit comments

Comments
 (0)