Category
stdlib | php-src-strict
Problem
array_chunk([], $size, $preserve_keys) with an inline empty array literal throws LogicException ("first argument must be an array"). Zend returns array().
A variable holding [] works ($a = []; array_chunk($a, 2) is fine), so the bug is in compile-time literal lowering / builtin arg materialization for empty Expr_Array.
php-src reference
Repro
test/repro/maintainer_gap_array_chunk_empty_literal.php:
<?php
var_export(array_chunk([], 2, true));
echo "\n";
php test/repro/maintainer_gap_array_chunk_empty_literal.php # Zend: array ()
php bin/vm.php test/repro/maintainer_gap_array_chunk_empty_literal.php # VM: LogicException
Control (must stay green):
$a = [];
var_export(array_chunk($a, 2, true));
| Engine |
Inline [] |
$a = [] |
| Zend PHP 8.4+ |
array() |
array() |
| This compiler VM |
LogicException |
array() |
Scope
| Module |
Path |
| Compiler |
empty array literal → VM array value for builtin calls |
| VM builtin |
ext/standard/array_chunk.php type guard should accept empty arrays |
| JIT/AOT |
same literal lowering path |
| Tests |
test/compliance/cases/stdlib/array_chunk_empty_literal.phpt |
Done when
Related
Category
stdlib| php-src-strictProblem
array_chunk([], $size, $preserve_keys)with an inline empty array literal throwsLogicException("first argument must be an array"). Zend returnsarray().A variable holding
[]works ($a = []; array_chunk($a, 2)is fine), so the bug is in compile-time literal lowering / builtin arg materialization for emptyExpr_Array.php-src reference
ext/standard/array.c—php_array_chunkearly return on empty inputZend/zend_operators.c— empty array handlingRepro
test/repro/maintainer_gap_array_chunk_empty_literal.php:Control (must stay green):
[]$a = []array()array()LogicExceptionarray()Scope
ext/standard/array_chunk.phptype guard should accept empty arraystest/compliance/cases/stdlib/array_chunk_empty_literal.phptDone when
array_chunk([], …)returns[]on VM[](auditarray_pad,array_merge, …)Related