Skip to content

Commit 447ca83

Browse files
committed
fixup! Support first-class callables in const-expressions
1 parent 628a8c6 commit 447ca83

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
FCC in initializer errors for missing function with FQN matching global function.
3+
--FILE--
4+
<?php
5+
6+
namespace Foo;
7+
8+
const Closure = \Foo\strrev(...);
9+
10+
var_dump(Closure);
11+
var_dump((Closure)("abc"));
12+
13+
?>
14+
--EXPECTF--
15+
Fatal error: Uncaught Error: Call to undefined function Foo\strrev() in %s:%d
16+
Stack trace:
17+
#0 {main}
18+
thrown in %s on line %d
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
FCC in initializer errors for missing function with FQN matching global function.
3+
--FILE--
4+
<?php
5+
6+
namespace Foo;
7+
8+
const Closure = namespace\strrev(...);
9+
10+
var_dump(Closure);
11+
var_dump((Closure)("abc"));
12+
13+
?>
14+
--EXPECTF--
15+
Fatal error: Uncaught Error: Call to undefined function Foo\strrev() in %s:%d
16+
Stack trace:
17+
#0 {main}
18+
thrown in %s on line %d

Zend/zend_ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,12 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
10021002
zend_string *function_name_lc = zend_string_tolower(function_name);
10031003
fptr = zend_fetch_function(function_name_lc);
10041004
zend_string_release(function_name_lc);
1005+
if (!fptr && ast->child[0]->attr != ZEND_NAME_FQ) {
1006+
const char *backslash = zend_memrchr(ZSTR_VAL(function_name_lc), '\\', ZSTR_LEN(function_name_lc));
1007+
if (backslash) {
1008+
fptr = zend_fetch_function_str(backslash + 1, ZSTR_LEN(function_name_lc) - (backslash - ZSTR_VAL(function_name_lc) + 1));
1009+
}
1010+
}
10051011
if (!fptr) {
10061012
zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(function_name));
10071013
return FAILURE;

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11262,6 +11262,9 @@ static void zend_compile_const_expr_fcc(zend_ast **ast_ptr)
1126211262
zend_string *name = zend_resolve_function_name(Z_STR_P(name_ast_zv), name_ast->attr, &is_fully_qualified);
1126311263
zval_ptr_dtor_nogc(name_ast_zv);
1126411264
ZVAL_STR(name_ast_zv, name);
11265+
if (is_fully_qualified) {
11266+
name_ast->attr = ZEND_NAME_FQ;
11267+
}
1126511268
break;
1126611269
}
1126711270
case ZEND_AST_STATIC_CALL: {

0 commit comments

Comments
 (0)