diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index e0a5023a..5fae5e63 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1036,8 +1036,11 @@ class CompilerBase extends \PhpAot\Core\Translator continue; } if ($item instanceof Node\Expr\ArrayItem) { + $oriInAssignExpr = $this->inAssignExpr; + $this->inAssignExpr = true; $var = $this->parseIdentifier($item->value); - if (!$this->hasVar($var)) { + $this->inAssignExpr = $oriInAssignExpr; + if ($this->isVarExpr($item->value) and !$this->hasVar($var)) { $this->addLocalVar($var, self::TYPE_VAR); } $code .= "{$var} = {$tmpVar}.item({$k}); "; @@ -1199,7 +1202,11 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parseReturn(mixed $v): string { if ($v->expr === null) { - return 'return;'; + if ($this->functionDef->returnType === self::TYPE_VOID) { + return 'return;'; + } else { + return 'return php::null;'; + } } // 实际函数的返回值 $type = $this->detectExprType($v->expr); diff --git a/tests/misc/1.phpt b/tests/misc/1.phpt index 26401810..d9552ae4 100644 --- a/tests/misc/1.phpt +++ b/tests/misc/1.phpt @@ -1,5 +1,5 @@ --TEST-- -mixed/1.phpt +mixed: 1 --FILE-- = 0; $i = $i - 2) { + // 奇数位需要调换的偶数 + if ($A[$i] % 2 !== $i % 2) { + // 偶数位不需要调换的偶数 + while ($A[$j] % 2 === $j % 2) { + $j = $j - 2; + } + [$A[$i], $A[$j]] = [$A[$j], $A[$i]]; + } + } + return $A; +} +?> +--EXPECT-- +Array +( + [0] => 4 + [1] => 5 + [2] => 2 + [3] => 7 +) +