Skip to content

Language: throw expressions (PHP 8.0) — parse and lowering in expression context #3802

Description

@PurHur

Category

language

Problem

PHP 8.0 throw expressions allow throw anywhere an expression is valid (ternary arms, null-coalesce, short-circuit, parentheses). This compiler’s php-cfg pass does not handle PhpParser\Node\Expr\Throw_ inside expression trees — parse fails before compile.

This is syntax/lowering, distinct from #195 (builtin Exception class registration for catch).

php-src reference

Repro (failure today)

<?php
// ternary arm
echo (false ? 1 : throw new LogicException('x'));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'

Zend PHP 8+: uncaught LogicException: x (non-zero exit)

This compiler:

RuntimeException: Unknown Expr Type Expr_Throw
  in vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php

Also fails for: ($x ?? throw new Exception('missing')), true && throw new Exception('x').

Scope (this repo)

Layer Path Notes
php-cfg vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php parseExprNode() / parseExpr_Throw
Patch patches/php-cfg-*.patch if vendor fix required
Compiler lib/Compiler.php lower throw-expr to TYPE_THROW with value operand
VM/JIT lib/VM.php, lib/JIT.php reuse existing throw opcodes
Tests test/compliance/cases/language/throw_expression.phpt ternary + coalesce cases

Done when

  • Ternary and null-coalesce repros compile and throw at runtime (after Language: throw expressions and Exception object propagation #195 lands, use LogicException or user class)
  • Short-circuit && / \|\| throw arm matches Zend evaluation order
  • ./script/ci-fast.sh --filter throw_expression green
  • docs/capabilities-syntax.md notes throw-expressions VM/JIT/AOT status

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/ci-fast.sh --filter throw_expression'

Dependencies

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions