Skip to content

Regression: in_array()/array_merge()/array_flip()/array_map() null array coerce — Zend TypeError (ext/standard/array.c, re-#21771) #21916

Closed

Description

@PurHur

Category

bug · php-src-strict · stdlib / array null TypeError batch

Problem

Against the Docker Zend 8.2 reference, these builtins must TypeError on a null array operand. The VM silently coerces (legacy empty/false results) on default and PHP_COMPILER_PROFILE=8.4.

Repro Zend 8.2 (2026-07-21) VM (2026-07-21)
in_array(1, null) TypeError (haystack must be array) false
array_merge(null) TypeError array()
array_flip(null) TypeError array()
array_map(strval(...), null) TypeError array()
array_sum(null) TypeError 0

Peers: #21914 (count/sizeof), #21915 (array_keys). Same root cause as inverted #21771 (8.4 DEP claim must not break 8.2 reference TypeError).

php-src reference

PHP implementation target

  • Shared null→TypeError guard for array operands in ext/standard/ (+ JIT stubs) under reference profile
  • Prefer one helper reused by listed builtins; VM/JIT/AOT agree
  • No new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/array_null_batch.php <<'"'"'PHP'"'"'
<?php
$cases = [
  "in_array" => fn() => in_array(1, null),
  "array_merge" => fn() => array_merge(null),
  "array_flip" => fn() => array_flip(null),
  "array_map" => fn() => array_map(strval(...), null),
  "array_sum" => fn() => array_sum(null),
];
foreach ($cases as $name => $fn) {
  try { var_export($fn()); echo " ($name)\n"; }
  catch (Throwable $e) { echo $name, " ", get_class($e), "\n"; }
}
PHP
php /tmp/array_null_batch.php
php bin/vm.php /tmp/array_null_batch.php
'

Done when

  • Each listed call throws Zend-identical TypeError on VM + JIT (reference profile)
  • Compliance .phpt under test/compliance/cases/array/
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 21, 2026
  2. PurHur commented on Jul 21, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

    Pillar probe (in progress): make bootstrap-selfhost-link still running in docker-exec; inventory/release-readiness queued after lock clears.

    Plan: remove soft-null for Z_PARAM_ARRAY on in_array/array_merge/array_flip/array_map/array_sum (mirror #21915 array_keys) — always TypeError like php-src; update #21771 soft_forward84 expectations.

  3. PurHur commented on Jul 21, 2026

    @PurHur
    OwnerAuthor

    Merged in #21955

    Verification: VM + JIT repro green; PROFILE=8.4 TypeError (no soft-null); Docker AOT array_sum(null) exit 134; AotTest array_sum_null_typeerror OK. Also closes #21926 (array_sum).

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 machinebugSomething isn't workingimplementation-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