Skip to content

Stdlib: array_chunk() rejects inline empty array literal — must return [] (ext/standard/array.c) #9349

Description

@PurHur

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

  • Inline array_chunk([], …) returns [] on VM
  • Non-empty literal and variable forms unchanged
  • No regression on other builtins taking inline [] (audit array_pad, array_merge, …)

Related

Activity

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:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions