diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ee89eef0..c97b7ef2 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4039,12 +4039,17 @@ class CompilerBase extends \PhpAot\Core\Translator { $cb = function () use ($expr) { $code = $this->parseExpr($expr->expr); + if ($this->beforeStmtLines) { + $beforeCode = implode(PHP_EOL, $this->beforeStmtLines); + } else { + $beforeCode = ''; + } if ($this->isCallExpr($expr->expr)) { if ($this->lastNativeCall and $this->lastNativeCall->returnType === self::TYPE_VOID) { - return $code . ";\nreturn " . self::VALUE_NULL . ';'; + return $beforeCode . PHP_EOL . $code . ";" . PHP_EOL . "return " . self::VALUE_NULL . ';'; } } - return 'return ' . $code . ';'; + return $beforeCode . PHP_EOL . 'return ' . $code . ';'; }; return $this->genClosure($expr, $expr->params, $cb, [], true); } diff --git a/src/Php/Generator/ClosureGenerator.php b/src/Php/Generator/ClosureGenerator.php index a7dde09c..4faad75d 100644 --- a/src/Php/Generator/ClosureGenerator.php +++ b/src/Php/Generator/ClosureGenerator.php @@ -37,12 +37,16 @@ trait ClosureGenerator $oriCeWrappers = $this->ceWrappers; $oriArgs = $this->arguments; $oriInClosure = $this->inClosure; + $oriBeforeStmtLines = $this->beforeStmtLines; + $oriAfterStmtLines = $this->afterStmtLines; $this->objects = []; $this->objectWrappers = []; $this->ceWrappers = []; $this->arguments = []; $this->inClosure = true; + $this->beforeStmtLines = []; + $this->afterStmtLines = []; $this->indentLevel++; @@ -70,8 +74,6 @@ trait ClosureGenerator $this->indentLevel--; $code .= '};' . PHP_EOL; - $this->beforeStmtLines[] = $code; - $useVars = []; if ($uses) { foreach ($uses as $useItem) { @@ -95,6 +97,9 @@ trait ClosureGenerator $this->ceWrappers = $oriCeWrappers; $this->arguments = $oriArgs; $this->inClosure = $oriInClosure; + $this->beforeStmtLines = $oriBeforeStmtLines; + $this->afterStmtLines = $oriAfterStmtLines; + $this->beforeStmtLines[] = $code; if ($this->methodDef) { return 'php::newClosure(' . $tmpVar . ', { ' . implode(', ', $useVars) . ' }, this_)'; diff --git a/tests/aot/arrow-func-2.phpt b/tests/aot/arrow-func-2.phpt new file mode 100644 index 00000000..56ba5c2d --- /dev/null +++ b/tests/aot/arrow-func-2.phpt @@ -0,0 +1,17 @@ +--TEST-- +arrow function 2 +--FILE-- + var_dump(0, ...$array); + $fn1(); +} +?> +--EXPECT-- +int(0) +int(1) +int(5) +int(9) + diff --git a/tests/aot/static_prop_write.phpt b/tests/aot/static_prop_write.phpt new file mode 100644 index 00000000..7b71c01d --- /dev/null +++ b/tests/aot/static_prop_write.phpt @@ -0,0 +1,32 @@ +--TEST-- +Static Class Property Read/Write Test +--FILE-- +errorHandler = $errorHandler; + ($this->errorHandler)(); + } +} + +class Worker +{ + public static ?stdClass $globalEvent = null; + public static string $eventLoopClass = 'Select'; + + public static function init() { + self::$globalEvent = new static::$eventLoopClass(); + self::$globalEvent->setErrorHandler(function ($exception) { + var_dump(__FUNCTION__); + }); + } +} + +function main() { + Worker::init(); +} +?> +--EXPECT-- +string(4) "init" \ No newline at end of file