diff --git a/bin/gen_stub.php b/bin/gen_stub.php index 9826d10c..0364cde8 100755 --- a/bin/gen_stub.php +++ b/bin/gen_stub.php @@ -4252,7 +4252,7 @@ class FileInfo { public bool $generateClassEntries = true; private bool $isUndocumentable = false; private bool $legacyArginfoGeneration = false; - private ?int $minimumPhpVersionIdCompatibility = PHP_80_VERSION_ID; + private ?int $minimumPhpVersionIdCompatibility = PHP_84_VERSION_ID; /** @param array $fileTags */ public function __construct(array $fileTags) { diff --git a/src/Php/AstNodeType.php b/src/Php/AstNodeType.php index e5e7baad..825c6b19 100644 --- a/src/Php/AstNodeType.php +++ b/src/Php/AstNodeType.php @@ -122,6 +122,14 @@ trait AstNodeType return $expr instanceof Node\Stmt\Break_; } + protected function isThrowExpr(NodeAbstract $expr): bool + { + if ($expr instanceof Node\Stmt\Expression) { + $expr = $expr->expr; + } + return $expr instanceof Expr\Throw_; + } + protected function isExitExpr(NodeAbstract $expr): bool { if ($expr instanceof Node\Stmt\Expression) { diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 352b1634..d1a1bed4 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3351,8 +3351,12 @@ class CompilerBase extends \PhpAot\Core\Translator $stmts = $stmts[0]->stmts; } $lastExpr = end($stmts); - if (!$this->isReturnExpr($lastExpr) and !$this->isExitExpr($lastExpr) and !$this->isBreakExpr($lastExpr)) { - $this->fatalError($case, 'switch case must end with return or break or exit, ' . $lastExpr->getType() . ' given'); + if (!$this->isReturnExpr($lastExpr) + and !$this->isExitExpr($lastExpr) + and !$this->isBreakExpr($lastExpr) + and !$this->isThrowExpr($lastExpr) + ) { + $this->fatalError($case, 'switch case must end with return/break/exit/throw, ' . $lastExpr->getType() . ' given'); } if ($condList) { @@ -3959,10 +3963,11 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parseThrow(mixed $expr): string { if (!$this->isVarExpr($expr->expr) and $expr->expr->getType() != self::EXPR_NEW) { - $this->fatalError($expr, 'The throw statement only accepts a object variable'); + $ex = $this->convertToObject($expr->expr); + } else { + $ex = $this->parseIdentifier($expr->expr); } - - return 'php::throwException(' . $this->parseIdentifier($expr->expr) . ')'; + return 'php::throwException(' . $ex . ')'; } protected function parseTryCatch(mixed $v): string