diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6f2cb288..3400e537 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4345,7 +4345,6 @@ class CompilerBase extends \PhpAot\Core\Translator { $cb = function () use ($expr) { $fnCode = $this->parseStmts($expr->stmts); - $fnCode = $this->genLocalVarDecl() . $fnCode; if (!$this->isReturnStmtInLastLine($expr->stmts)) { $fnCode .= 'return ' . self::VALUE_NULL . ';' . PHP_EOL; } diff --git a/src/Php/Generator/ClosureGenerator.php b/src/Php/Generator/ClosureGenerator.php index 2aa52d54..dafb7339 100644 --- a/src/Php/Generator/ClosureGenerator.php +++ b/src/Php/Generator/ClosureGenerator.php @@ -64,7 +64,8 @@ trait ClosureGenerator $this->addArgument('this_', self::TYPE_OBJECT); } - $code .= $bodyGenCb(); + $body = $bodyGenCb(); + $code .= $this->genLocalVarDecl() . $body; $this->indentLevel--; $this->context->inClosure = false; diff --git a/tests/aot/arrow_fn/004.phpt b/tests/aot/arrow_fn/004.phpt new file mode 100644 index 00000000..2f4a17fe --- /dev/null +++ b/tests/aot/arrow_fn/004.phpt @@ -0,0 +1,18 @@ +--TEST-- +arrow function +--FILE-- + $obj->add(new DateInterval($add)); + $newDate = $fn('P10D'); + echo $newDate->format('Y-m-d') . "\n"; +} + +function main() +{ + $date = new DateTimeImmutable('2000-01-01'); + foo($date); +} +?> +--EXPECT-- +2000-01-11 \ No newline at end of file