Category
stdlib
Status (expanded 2026-06-04 — implementation-ready)
Fourth-argument $preserve_keys is accepted by Zend but rejected at runtime in this compiler. Referenced repro path test/repro-maintainer/array_slice_preserve_keys.php was never committed — inline repro below.
Problem
array_slice($array, $offset, $length, $preserve_keys) accepts a fourth boolean argument in PHP. When true, returned slice must keep original keys (e.g. ['c'=>2,'d'=>3] from the tail). This compiler rejects four arguments at runtime.
php-src reference
Repro (failure today)
Save as repro_array_slice_preserve_keys.php:
<?php
$a = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
$r = array_slice($a, 2, 2, true);
echo implode(',', array_keys($r)), '|', implode(',', $r), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_array_slice_preserve_keys.php
php bin/vm.php repro_array_slice_preserve_keys.php
'
| Runtime |
Output |
| Zend PHP 8.x |
c,d|2,3 |
bin/vm.php |
LogicException: array_slice() requires two or three arguments in this compiler build |
Three-argument form must remain unchanged (reindex list keys when $preserve_keys omitted/false).
Scope (this repo)
| Layer |
Path |
Notes |
| VM |
ext/standard/array_slice.php, VmArray helper |
Parse 4th arg; copy keys when true |
| JIT |
lib/JIT/Builtin/Array*.php or JitArraySlice |
Optional 4th arg lowering |
| AOT |
fixture under test/fixtures/aot/cases/ |
|
| Tests |
test/compliance/cases/stdlib/array_slice_preserve_keys.phpt |
|
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter array_slice'
Related
Category
stdlibStatus (expanded 2026-06-04 — implementation-ready)
Fourth-argument
$preserve_keysis accepted by Zend but rejected at runtime in this compiler. Referenced repro pathtest/repro-maintainer/array_slice_preserve_keys.phpwas never committed — inline repro below.Problem
array_slice($array, $offset, $length, $preserve_keys)accepts a fourth boolean argument in PHP. Whentrue, returned slice must keep original keys (e.g.['c'=>2,'d'=>3]from the tail). This compiler rejects four arguments at runtime.php-src reference
ext/standard/array.c—PHP_FUNCTION(array_slice),preserve_keysbranch inphp_array_sliceRepro (failure today)
Save as
repro_array_slice_preserve_keys.php:c,d|2,3bin/vm.phpLogicException: array_slice() requires two or three arguments in this compiler buildThree-argument form must remain unchanged (reindex list keys when
$preserve_keysomitted/false).Scope (this repo)
ext/standard/array_slice.php,VmArrayhelperlib/JIT/Builtin/Array*.phporJitArraySlicetest/fixtures/aot/cases/test/compliance/cases/stdlib/array_slice_preserve_keys.phptDone when
c,d|2,3on VM (Dockerphp-compiler:22.04-dev)array_slice($a, 0, 2)on list still returns0,1keys./script/ci-fast.sh --filter array_slice_preservegreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter array_slice'Related