Skip to content

Regression: array_map(null, $array) identity form broken — TypeError/fatal (ext/standard/array.c) #9143

Description

@PurHur

Category

stdlib

Problem

Zend treats array_map(null, $array) as the single-array identity form: it returns a copy of $array without invoking a callback. This compiler mis-parses the null callback and raises TypeError: array_map(): Argument #2 ($array) must be of type array, null given (or fatals with no output) — a regression of closed #4539.

php-src reference

  • ext/standard/array.c — php_array_map() null-callback branch (ZEND_FCI_INITIALIZED guard)
  • Tests: ext/standard/tests/array/array_map_variation*.phpt

Repro

Create test/repro/maintainer_gap_array_map_null.php:

<?php
$out = array_map(null, [1, 2, 3]);
echo implode(',', $out), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_gap_array_map_null.php'
php test/repro/maintainer_gap_array_map_null.php

Zend:

1,2,3

This compiler (VM, 2026-06-17):

PHP Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, null given

(or empty output when wrapped in other calls)

Multi-array zip must remain unchanged:

<?php
var_export(array_map(null, [1,2], ['a','b'])); // Zend: array([0]=>array(1,'a'), ...)

Scope (this repo)

Area Path Action
Stdlib ext/standard/array_map.php Detect null callback + exactly one array → identity copy
VM builtin dispatch No special case in lib/VM.php — fix builtin
JIT lib/JIT/Builtin/ array_map lowering Mirror PHP guard when JIT supports array_map

PHP-in-PHP: implement in ext/standard/array_map.php; shared guard for JIT if lowered.

Done when (php-src-strict)

  • php bin/vm.php test/repro/maintainer_gap_array_map_null.php prints 1,2,3
  • Multi-array array_map(null, ...) still zips per Zend
  • Compliance guard under test/compliance/cases/stdlib/array_map_null_identity.phpt
  • JIT/AOT identity form green if array_map is JIT-supported in build

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter array_map_null'

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