Skip to content

Commit a2d5e9d

Browse files
Validate functions in nested task closures
1 parent 01b5cb8 commit a2d5e9d

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/scheduler.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ static bool php_parallel_scheduler_functions(zend_function *function, php_parall
158158
required = zend_fetch_function(Z_STR_P(name + 2));
159159
}
160160
break;
161+
case ZEND_DECLARE_LAMBDA_FUNCTION: {
162+
zend_string *key;
163+
zend_function *nested;
164+
165+
PARALLEL_COPY_OPLINE_TO_FUNCTION(function, opline, &key, &nested);
166+
167+
if (!php_parallel_scheduler_functions(nested, error)) {
168+
return false;
169+
}
170+
} break;
161171
}
162172

163173
if (name) {

tests/base/init_fcall_fix_004.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Missing function in nested closure fails task before execution
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('parallel')) {
6+
echo 'skip';
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
function dummy_func(): string { return 'value'; }
12+
13+
$runtime = new \parallel\Runtime();
14+
try {
15+
$runtime->run(function(){
16+
echo "task executed\n";
17+
return (static fn() => dummy_func())();
18+
})->value();
19+
} catch (\parallel\Runtime\Error\IllegalInstruction $e) {
20+
echo $e->getMessage();
21+
}
22+
?>
23+
--EXPECT--
24+
Task requires function dummy_func(), but dummy_func() is not defined in this Runtime. Define it in the Runtime bootstrap or pass it as a task argument with Closure::fromCallable('dummy_func').

0 commit comments

Comments
 (0)