[php-src] master: Merge branch 'PHP-8.6'
| From: | Arnaud Le Blanc | Date: | Wed, 25 Nov 2026 14:37:27 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144156@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-11-25T15:37:14+01:00
Commit: https://github.com/php/php-src/commit/ce41001a73f8f2838d59bc72681b15a176315758
Raw diff: https://github.com/php/php-src/commit/ce41001a73f8f2838d59bc72681b15a176315758.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix arrow functions not capturing variables in partial application args (#25732)
Changed paths:
A Zend/tests/partial_application/arrow_function_implicit_bind.phpt
M Zend/zend_compile.c
Diff:
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--
+<?php
+
+function f($a, $b) {
+ return "$a $b";
+}
+
+class C {
+ public function m($a, $b) {
+ return "$a $b";
+ }
+
+ public static function s($a, $b) {
+ return "$a $b";
+ }
+}
+
+$a = 'a';
+$o = new C;
+
+var_dump((fn() => 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 e8d462ed8efa..f2cf095ac03c 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -8855,6 +8855,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++) {