Skip to content

Language: internal builtin exceptions must honor user try/catch (zend_exceptions.c) #4866

Description

@PurHur

Category

language · runtime · stdlib bridge

Problem

User try/catch blocks must intercept exceptions thrown from internal/builtin handlers the same way Zend does. Today:

  1. ValueError from builtins can be swallowed — substr_compare(..., -1) inside catch (ValueError) prints no throw and exits 0 on VM, while Zend catches.
  2. LogicException/TypeError from builtins ignore catch blocks — floor($object) inside catch (TypeError) either fatals through the handler (LogicException path) or silently continues (no throw), never entering the user catch.

Bare throw new ValueError(...) is catchable (probe14e green), so the bug is specific to exceptions raised from Internal::execute() / VM dispatch, not the catch machinery itself.

Related umbrella: #4178 (wrong exception type from builtins) — fix types and ensure they propagate into active catch frames.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_builtin_try_catch.php; echo zend:$?
php bin/vm.php test/repro-maintainer/parity_builtin_try_catch.php; echo vm:$?
'
Case Zend VM
substr_compare negative length in catch (ValueError) caught ValueError no throw
floor(object) in catch (TypeError) caught TypeError no throw

Repro script: test/repro-maintainer/parity_builtin_try_catch.php

Scope (this repo)

Area Files
VM lib/VM.php — internal handler exception dispatch into catch stack
VM lib/VM/ExceptionSupport.php — ValueError/TypeError bridging
Stdlib ext/standard/*.php — after VM fix, migrate LogicException → TypeError/ValueError (#4178)
Tests test/compliance/cases/language/builtin_try_catch.phpt

Done when

  • Repro prints caught ValueError + caught TypeError on VM (exit 0)
  • Uncaught builtin exceptions still fatal with exit 255 outside try
  • ./script/ci-fast.sh --filter builtin_try_catch green

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