Skip to content

Language: array spread of non-traversable string — Fatal error not TypeError (zend_execute.c) #4812

Description

@PurHur

Category

language

Problem

Spreading a non-array, non-Traversable value in an array literal (e.g. ...'ab') must raise a Zend Error Fatal: Only arrays and Traversables can be unpacked. This build throws TypeError with a similar message — wrong exception class and not catchable the same way as Zend.

php-src reference

Repro

test/tmp/repro-array-spread-string-fatal.php:

<?php
declare(strict_types=1);
try {
    var_export([...[1, 2], ...'ab']);
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
./script/docker-exec.sh -- bash -lc 'php test/tmp/repro-array-spread-string-fatal.php; php bin/vm.php test/tmp/repro-array-spread-string-fatal.php'
Zend This compiler
Severity Fatal Error (uncaught in try) TypeError caught in try
Message Only arrays and Traversables can be unpacked Only arrays and Traversables can be unpacked

Scope

Module Path
VM array spread / unpack validation
Tests compliance case

Done when

  • Repro is fatal on VM (not catchable TypeError), matching Zend
  • Message matches php-src

Related

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 3, 2026
  2. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-a — starting this run

  3. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    Merged via #6285.

    Fix: Array-literal spread of non-array/non-Traversable operands now raises uncatchable fatal Error (LogicException → exit 255), matching Zend — not catchable TypeError.

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    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"
    '

    → Fatal error: Only arrays and Traversables can be unpacked in … on line 4, exit 255, OK (2 tests).

  4. PurHur commented on Jul 30, 2026

    @PurHur
    OwnerAuthor

    Cleanup: deleting leftover test/tmp/ scratch repro for this closed issue — same coverage lives under test/compliance/cases/ (see PR chore/cleanup-stale-test-tmp-repros).

  5. PurHur commented on Jul 30, 2026

    @PurHur
    OwnerAuthor

    Cleanup follow-up: merged #25413 — test/tmp scratch repro removed.

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