diff --git a/src/Php/Generator/ClosureGenerator.php b/src/Php/Generator/ClosureGenerator.php index 518da8ed..b72fe82c 100644 --- a/src/Php/Generator/ClosureGenerator.php +++ b/src/Php/Generator/ClosureGenerator.php @@ -101,6 +101,9 @@ trait ClosureGenerator // 使用 lambda 函数来对 static 变量进行赋值 $this->context = new FunctionContext(); + // C++ lambda 使用 & 捕获了当前函数的所有局部变量,可直接使用,不需要再声明,将其作为 arguments 来处理,隐式使用 + $this->context->arguments = $oriCtx->localVars; + $code .= '([&](){' . PHP_EOL; $body = $cb(); $code .= $this->genLocalVarDecl(); diff --git a/tests/aot/static-vars-02.phpt b/tests/aot/static-vars-02.phpt new file mode 100644 index 00000000..57535817 --- /dev/null +++ b/tests/aot/static-vars-02.phpt @@ -0,0 +1,16 @@ +--TEST-- +static variables +--FILE-- + 'ten'); + print_r($arr3); +} +?> +--EXPECT-- +Array +( + [100] => ten +) \ No newline at end of file