From 5dbd7a804d2da562ab003ddeea7873da48922433 Mon Sep 17 00:00:00 2001 From: Andrej Mihaliak Date: Wed, 25 Nov 2026 09:08:48 +0100 Subject: [PATCH 1/3] Fix arrow functions not capturing variables in partial application args find_implicit_binds_recursively() walks the child nodes of an arrow function's body to find the variables it captures. The arguments of a partial application are kept in zend_ast_fcc.args instead, so a variable used only there was not captured: it was undefined in the arrow function and the partial application bound null. --- .../arrow_function_implicit_bind.phpt | 47 +++++++++++++++++++ Zend/zend_compile.c | 4 ++ 2 files changed, 51 insertions(+) create mode 100644 Zend/tests/partial_application/arrow_function_implicit_bind.phpt diff --git a/Zend/tests/partial_application/arrow_function_implicit_bind.phpt b/Zend/tests/partial_application/arrow_function_implicit_bind.phpt new file mode 100644 index 000000000000..80f6968447da --- /dev/null +++ b/Zend/tests/partial_application/arrow_function_implicit_bind.phpt @@ -0,0 +1,47 @@ +--TEST-- +PFA: arrow functions capture variables used in the bound arguments of a partial application +--FILE-- + f($a, ?))()('b')); +var_dump((fn() => array_map(f($a, ?), ['b'])[0])()); +var_dump((fn() => $o->m($a, ?))()('b')); +var_dump((fn() => C::s($a, ?))()('b')); +var_dump((fn() => f(a: $a, b: ?))()('b')); +var_dump((fn() => f($a, ...))()('b')); +var_dump((fn() => f(f($a, ?)('b'), ?))()('c')); +var_dump((fn() => f((fn() => $a)(), ?))()('b')); + +/* Captured by value when the arrow function is created, like any other variable. */ +$fn = fn() => f($a, ?); +$a = 'changed'; +var_dump($fn()('b')); + +?> +--EXPECT-- +string(3) "a b" +string(3) "a b" +string(3) "a b" +string(3) "a b" +string(3) "a b" +string(3) "a b" +string(5) "a b c" +string(3) "a b" +string(3) "a b" diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index abed76366229..61274db1ba7d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -8813,6 +8813,10 @@ static void find_implicit_binds_recursively(closure_info *info, zend_ast *ast) { zend_hash_copy(&info->uses, &inner_info.uses, NULL); } zend_hash_destroy(&inner_info.uses); + } else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) { + /* The arguments of a partial application are not child nodes. */ + const zend_ast_fcc *fcc_ast = (const zend_ast_fcc *) ast; + find_implicit_binds_recursively(info, fcc_ast->args); } else if (!zend_ast_is_special(ast)) { uint32_t i, children = zend_ast_get_num_children(ast); for (i = 0; i < children; i++) { From e0aafaca064f0285faf69b248e4ac298c70ee18a Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Wed, 25 Nov 2026 15:34:43 +0100 Subject: [PATCH 2/3] [ci skip] NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 7de98e000e1b..cf52ff22b81e 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,8 @@ PHP NEWS . Fixed propagation of public(set) of readonly trait property. (ilutov) . Fixed bug GH-25313 (Assertion !EG(exception) in ZEND_FE_FREE when unpacking a generator into a by-ref parameter throws). (ndossche) + . Fixed arrow functions not capturing variables in partial application args. + (mihaliak) - Curl: . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire) From 907450991bc541fc1496a93d791fc872ca8a8365 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Wed, 25 Nov 2026 15:36:28 +0100 Subject: [PATCH 3/3] [ci skip] NEWS --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index fab20eaea3eb..26a495a6ddb3 100644 --- a/NEWS +++ b/NEWS @@ -44,9 +44,9 @@ PHP NEWS . Fixed propagation of public(set) of readonly trait property. (ilutov) . Fixed bug GH-25313 (Assertion !EG(exception) in ZEND_FE_FREE when unpacking a generator into a by-ref parameter throws). (ndossche) + . Fixed float literals losing precision in AST export. (Jorg Sowa) . Fixed arrow functions not capturing variables in partial application args. (mihaliak) - . Fixed float literals losing precision in AST export. (Jorg Sowa) - Curl: . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)