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
Related
Category
languageProblem
Spreading a non-array, non-Traversable value in an array literal (e.g.
...'ab') must raise a ZendErrorFatal:Only arrays and Traversables can be unpacked. This build throwsTypeErrorwith a similar message — wrong exception class and not catchable the same way as Zend.php-src reference
Zend/zend_execute.c—ZEND_ADD_ARRAY_ELEMENT/ unpackZend/zend_operators.c—zend_throw_error()Repro
test/tmp/repro-array-spread-string-fatal.php:./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'Error(uncaught in try)TypeErrorcaught in tryOnly arrays and Traversables can be unpackedOnly arrays and Traversables can be unpackedScope
Done when
TypeError), matching ZendRelated