Category
language
Problem
PHP supports array destructuring with spread: [$head, ...$tail] = $array (and keyed variants). Zend compiles this in zend_compile.c by assigning sequential elements then merging the remainder.
This compiler’s php-cfg fork (vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php::parseListAssignment) walks list items but ignores $item->unpack, so spread arms are treated like ordinary numeric slots — wrong variables receive values or compile fails.
Array-literal spread ([...$a]) works via TYPE_ARRAY_SPREAD; list-assign spread is a separate lowering path.
php-src reference
Repro (failure today)
<?php
$src = [1, 2, 3, 4];
[$a, ...$rest] = $src;
echo $a, ':', implode(',', $rest), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php 2>&1
'
| Runtime |
Expected |
Typical today |
| Zend PHP 8.x |
1:2,3,4 |
— |
bin/vm.php |
same |
wrong values, compile error, or spread arm ignored |
Keyed spread (stretch goal in same issue or follow-up):
['x' => $x, ...$others] = ['x' => 1, 'y' => 2];
Scope (this repo)
| Module |
Path |
| php-cfg |
patches/php-cfg-list-spread.patch (new) — teach parseListAssignment unpack arms |
| Compiler |
lib/Compiler.php — opcodes after TYPE_LIST_UNPACK_CHECK for spread tail |
| VM / JIT |
lib/VM.php, lib/JIT/ListUnpackHelper.php — append remaining list elements into $rest array |
| Tests |
test/compliance/cases/language/list_destructuring_spread.phpt |
Done when
Related
Links
Category
languageProblem
PHP supports array destructuring with spread:
[$head, ...$tail] = $array(and keyed variants). Zend compiles this inzend_compile.cby assigning sequential elements then merging the remainder.This compiler’s php-cfg fork (
vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php::parseListAssignment) walks list items but ignores$item->unpack, so spread arms are treated like ordinary numeric slots — wrong variables receive values or compile fails.Array-literal spread (
[...$a]) works viaTYPE_ARRAY_SPREAD; list-assign spread is a separate lowering path.php-src reference
Zend/zend_compile.c— list assignment with unpackZend/zend_execute.c—ZEND_ASSIGNlist unpack runtimezend_language_parser.y—array_elementwithT_ELLIPSISRepro (failure today)
1:2,3,4bin/vm.phpKeyed spread (stretch goal in same issue or follow-up):
Scope (this repo)
patches/php-cfg-list-spread.patch(new) — teachparseListAssignmentunpack armslib/Compiler.php— opcodes afterTYPE_LIST_UNPACK_CHECKfor spread taillib/VM.php,lib/JIT/ListUnpackHelper.php— append remaining list elements into$restarraytest/compliance/cases/language/list_destructuring_spread.phptDone when
1:2,3,4on VM matching Zend[$a, &$b, ...$c]matches Zend when supported by php-parser./script/ci-fast.sh --filter list_destructuring_spreadgreenRelated
Links