Category
language
Problem
Throw expressions outside throw; statements are not lowered. Assignment RHS $x = throw new Exception('e') fails in php-cfg:
Unknown Expr Type Expr_Throw
Distinct from null-coalesce throw (#3462) and match throw arms (#3398).
php-src reference
Zend/zend_compile.c — zend_compile_throw as expression (zend_ast throw expr)
Zend/zend_execute.c — ZEND_THROW with unused result slot
- PHP RFC: Throw Expression (PHP 8.0)
Repro (today)
<?php
function f(): int {
$x = throw new LogicException('abort');
return $x;
}
try {
f();
} catch (LogicException $e) {
echo $e->getMessage();
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Zend: prints abort (after #3371 / #195 register LogicException).
This compiler: compile fatal Unknown Expr Type Expr_Throw.
Requires #3371 / #195 for builtin exception classes before catch path is meaningful.
Scope (this repo)
| Path |
Notes |
vendor/ircmaxell/php-cfg |
Map Expr_Throw in assignment/return/comma contexts |
lib/Compiler.php |
Lower throw-expr → TYPE_THROW + unreachable merge |
lib/VM.php |
Propagate exception, no assign to LHS |
| Tests |
test/compliance/cases/language/throw_expression_assign.phpt |
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter throw_expression_assign'
Related
Category
languageProblem
Throw expressions outside
throw;statements are not lowered. Assignment RHS$x = throw new Exception('e')fails in php-cfg:Distinct from null-coalesce throw (#3462) and match throw arms (#3398).
php-src reference
Zend/zend_compile.c—zend_compile_throwas expression (zend_astthrow expr)Zend/zend_execute.c—ZEND_THROWwith unused result slotRepro (today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php' php repro.phpZend: prints
abort(after #3371 / #195 registerLogicException).This compiler: compile fatal
Unknown Expr Type Expr_Throw.Requires #3371 / #195 for builtin exception classes before catch path is meaningful.
Scope (this repo)
vendor/ircmaxell/php-cfgExpr_Throwin assignment/return/comma contextslib/Compiler.phpTYPE_THROW+ unreachable mergelib/VM.phptest/compliance/cases/language/throw_expression_assign.phptDone when
abortonce Language: Throwable / Error / TypeError / ValueError — builtin exception hierarchy (Zend zend_exceptions.c parity) #3371 green$x = throw ...never assigns to$x./script/ci-fast.sh --filter throw_expression_assigngreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter throw_expression_assign'Related
?? throw