Skip to content

Language: bare throw; rethrow — parse error in catch block (Zend/zend_compile.c) #17691

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

Zend PHP 8.0+ allows a bare throw; inside a catch block to rethrow the active exception. This compiler rejects the construct at parse time (unexpected token ";"), so exception propagation chains cannot match php-src.

Repro Zend 8.2+ VM (2026-07-10)
catch (Ex $e) { throw; } rethrows to outer catch, prints inner Fatal error: syntax error, unexpected token ";"

php-src reference

PHP implementation target

  • lib/Parser/ / compile pipeline — accept throw; as rethrow when inside catch scope
  • lib/VM.php / lib/JIT/ — propagate active exception object without a new expr
  • VM/JIT/AOT must agree on rethrow semantics

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_bare_throw_rethrow.php'

Done when

  • test/repro/maintainer_gap_bare_throw_rethrow.php prints inner and exits 0 on VM
  • JIT repro green for the same script
  • Compliance .phpt guard under test/compliance/cases/language/bare_throw_rethrow.phpt
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 10, 2026
  2. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-a — starting this run

  3. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #17705.

    Bare `throw;` catch rethrow was already implemented on the PHP 8.4 forward profile (`SourceBareThrowRewriter` → `TYPE_RETHROW`). This PR adds the missing maintainer-gap repro and compliance guard.

    Verification (all green):

    • `php bin/vm.php test/repro/maintainer_gap_bare_throw_rethrow.php` → `inner`
    • `PHP_COMPILER_PROFILE=8.4 php bin/jit.php test/repro/maintainer_gap_bare_throw_rethrow.php` → `inner`
    • `PHP_COMPILER_PROFILE=8.4 vendor/bin/phpunit test/compliance/VMTest.php --filter bare_throw_rethrow` → OK
    • `TryCatchComplianceTest::testBareThrow*` → OK

    Reference profile (8.2) correctly rejects bare `throw;` per Zend; enable via `PHP_COMPILER_PROFILE=8.4` or source pragma `// php-compiler-language-profile=8.4`.

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 / JITbugSomething isn't workingimplementation-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