Skip to content

Fix array literal spread non-traversable fatal Error (#4812) - #6285

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4812-array-spread-fatal
Jun 5, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4812-array-spread-fatal

Conversation

@PurHur

@PurHur PurHur commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Array-literal spread ([...$x]) of non-array/non-Traversable operands now raises an uncatchable fatal Error via LogicException, matching Zend zend_execute.c (zend_throw_error / E_ERROR) instead of catchable TypeError.
  • VM TYPE_ARRAY_SPREAD no longer routes this through dispatchVmTypeError; fatal bypasses user try/catch.
  • Records array-literal source line on TYPE_ARRAY_SPREAD opcodes for Zend-style in file on line N messages.

php-src reference: Zend/zend_execute.c array unpack

PHP implementation: lib/VM/ArraySpread.php, lib/VM.php, lib/Compiler.php

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/tmp/repro-array-spread-string-fatal.php; echo exit:$?
php bin/vm.php test/tmp/repro-array-spread-string-fatal.php; echo exit:$?
vendor/bin/phpunit test/compliance/VMTest.php --filter "array_spread_non_traversable_fatal|array_literal_unpack_spread"
'

Output (VM path):

Fatal error: Only arrays and Traversables can be unpacked in /compiler/test/tmp/repro-array-spread-string-fatal.php on line 4
exit:255
OK (2 tests, 3 assertions)

Closes #4812

Made with Cursor

Zend treats non-traversable array-literal unpack as E_ERROR fatal, not
catchable TypeError. Route VM spread validation through LogicException
with the php-src message and add compliance coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 6b86fb4 into master Jun 5, 2026
@PurHur
PurHur deleted the agent/issue-4812-array-spread-fatal branch June 5, 2026 17:23
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: array spread of non-traversable string — Fatal error not TypeError (zend_execute.c)

1 participant