Skip to content

Language: default engine-thrown Throwable getCode() to 0 (#22945)#22951

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-22945-engine-getcode-default
Jul 25, 2026
Merged

Language: default engine-thrown Throwable getCode() to 0 (#22945)#22951
PurHur merged 1 commit into
masterfrom
agent/issue-22945-engine-getcode-default

Conversation

@PurHur

@PurHur PurHur commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Engine-bridged Error / TypeError / DivisionByZeroError left ExceptionSupport::PROP_CODE unset in BuiltinExceptionSupport::materializeThrowable(), so Throwable::getCode() fatals on uninitialized Variable::$integer.
  • Stamp default code = 0 to match php-src zend_throw_exception / zend_exception_get_props; fold materializeDivisionByZeroError() onto the shared path (net shrink of duplicated ObjectEntry setup).
  • Compliance guard: test/compliance/cases/language/engine_throwable_getcode_default.phpt.
  • Regenerated docs/bootstrap-inventory.md (OK 6517/6517).

Closes #22945

php-src reference

  • Zend/zend_exceptions.c — default throwable code is 0
  • PHP-in-PHP only (lib/VM/BuiltinExceptionSupport.php); no C runtime changes

Test plan

  • Issue repro (host): Zend + php bin/vm.php /tmp/engine_getcode.php → all codes match
  • vendor/bin/phpunit --filter engine_throwable_getcode_default test/compliance/VMTest.php → OK
  • Related: exception_throw_code|exception_throw_caught|error_exception → OK
  • php script/bootstrap-inventory.php --checkOK 6517/6517
  • ./script/ci-fast.sh (in flight in Docker)

Verification transcript

=== ZEND ===
undef Error code=0
type TypeError code=0
div DivisionByZeroError code=0
user TypeError code=0
userErr Error code=7

=== VM (after fix) ===
undef Error code=0
type TypeError code=0
div DivisionByZeroError code=0
user TypeError code=0
userErr Error code=7

OK (1 test, 1 assertion)  # engine_throwable_getcode_default
OK 6517/6517              # bootstrap-inventory --check

C runtime: 0 lines added; PHP path only (duplicated DivisionByZero materializer removed).

Made with Cursor

materializeThrowable left PROP_CODE unset, so getCode() fatals on
engine-bridged Error/TypeError/DivisionByZeroError. Match zend_exceptions
default code=0; fold DivisionByZero materialize onto the shared path.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Regression: engine-thrown Error/TypeError getCode() crashes — code property uninitialized (Zend/zend_exceptions.c)

1 participant