Skip to content

Language: internal builtin exceptions honor user try/catch (#4866) - #7551

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4866-builtin-try-catch
Jun 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4866-builtin-try-catch

Conversation

@PurHur

@PurHur PurHur commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Void (FUNCCALL_EXEC_NORETURN) internal builtin calls no longer skip handler bodies when returnVar is null — validation and throws (e.g. substr_compare() negative length → ValueError) now run in void context.
  • LogicException raised from stdlib internal handlers is bridged into active user catch frames instead of bypassing them as engine fatals.

Closes #4866

php-src reference

  • Zend/zend_exceptions.c — zend_throw_exception_internal, active try_catch_array

PHP implementation

  • lib/VM.php — executeInternalHandler(), dispatchVmLogicException()
  • lib/VM/BuiltinExceptionSupport.php — materializeLogicException()

Verification

./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:$?
vendor/bin/phpunit --filter builtin_try_catch
'

Output:

caught ValueError
caught TypeError
zend:0
caught ValueError
caught TypeError
vm:0
OK (4 tests, 4 assertions)

Made with Cursor

Ensure internal handlers always receive a scratch returnVar so late-throwing
builtins like substr_compare() still raise in void context, and bridge
LogicException from stdlib handlers into active user catch frames.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 3d6931d into master Jun 7, 2026
@PurHur
PurHur deleted the agent/issue-4866-builtin-try-catch branch June 7, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant