Skip to content

Stdlib: max()/min(...$stringKeyedArray) crashes — Zend ArgumentCountError (ext/standard/array.c, VmMinMax.php) #23449

Description

@PurHur

Category

bug · php-src-strict · stdlib · min/max / argument unpacking

Problem

Unpacking an array with string keys into max() / min() becomes named arguments. Zend rejects that with ArgumentCountError (max() expects at least 1 argument, 0 given — named keys do not count as positional values). The VM instead hits ext/standard/VmMinMax.php and fatals:

Error: Call to a member function resolveIndirect() on null (after Undefined array key 0).

Verified 2026-07-26 (host Zend 8.2 vs php bin/vm.php):

Repro Zend 8.2+ VM (2026-07-26)
max(...["a"=>1,"b"=>2]) ArgumentCountError: max() expects at least 1 argument, 0 given Warning Undefined array key 0 in VmMinMax.php:162 then Error: … resolveIndirect() on null
min(...["a"=>3,"b"=>1]) same ArgumentCountError for min same VM crash
max(...["0"=>5,"1"=>9]) (numeric string keys) 9 9 (OK)

php-src reference

PHP implementation target

  • ext/standard/VmMinMax.phpcollectValues() must not assume calledArgs[0] when string-key unpack left argc inconsistent; throw Zend-compatible ArgumentCountError when no positional values remain
  • Shared call/named-arg path in lib/ if unpack already should reject unknown named params before enter
  • PHP-in-PHP only; no new C runtime

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/max_unpack.php <<'"'"'PHP'"'"'
<?php
try {
  var_export(max(...["a" => 1, "b" => 2]));
  echo "\n";
} catch (Throwable $e) {
  echo get_class($e), ":", $e->getMessage(), "\n";
}
PHP
php /tmp/max_unpack.php
php bin/vm.php /tmp/max_unpack.php'

Done when

  • VM throws ArgumentCountError matching Zend message for max/min string-key unpack (no resolveIndirect Error)
  • Numeric-key unpack and normal variadic/max($array) paths still match Zend
  • Compliance .phpt under test/compliance/cases/
  • php-src-strict; no php-compiler-strict shortcut

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 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