Skip to content

Too few arguments to a user function or method are padded with defaults instead of throwing ArgumentCountError #175

Closed

Description

@blacktrs

Summary

Too few arguments to a user function or method are padded with defaults instead of throwing ArgumentCountError.

Repro

<?php
class Svc { public function get(string $host, string $key): string { return "$host/$key"; } }
function two(int $a, int $b): int { return $a + $b; }

function attempt(string $label, callable $f): void {
    try { $v = var_export($f(), true); echo $label, ': ', $v, "\n"; }
    catch (ArgumentCountError $e) { echo $label, ": ArgumentCountError\n"; }
}

$s = new Svc();
$m = 'get';
$args = [];
$fn = 'two';
attempt('direct', fn() => two(1));
attempt('method', fn() => $s->get('h'));
attempt('dyn-method', fn() => $s->$m('h'));
attempt('dyn-method-spread', fn() => $s->$m(...['h']));
attempt('dyn-method-lead-spread', fn() => $s->$m('h', ...$args));
attempt('dyn-func', fn() => $fn(1));
attempt('call_user_func', fn() => call_user_func([$s, 'get'], 'h'));

Expected (php)

direct: ArgumentCountError
method: ArgumentCountError
dyn-method: ArgumentCountError
dyn-method-spread: ArgumentCountError
dyn-method-lead-spread: ArgumentCountError
dyn-func: ArgumentCountError
call_user_func: ArgumentCountError

Actual (manticore 7c149235, Darwin arm64)

direct: 1
method: 'h/'
dyn-method: 'h/'
dyn-method-spread: 'h/'
dyn-method-lead-spread: 'h/'
dyn-func: 1
call_user_func: 'h/'

Tracking

Known-bug repro: tests/aot/repro/wrong/too_few_arguments_not_thrown.php — bash tests/aot/xfail.sh -k too_few_arguments_not_thrown reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 11, 2026
  2. blacktrs commented on Oct 11, 2026

    @blacktrs
    ContributorAuthor

    Expected behaviour: two layers

    Runtime (always). Every call path that binds arguments to a user function/method must throw ArgumentCountError ("Too few arguments to function X::m(), N passed in %s on line %d and exactly|at least M expected") when a required parameter has no argument: direct, dynamic method/function name, call_user_func*, spread (...$args, including a leading fixed arg + spread), closures, constructors. Today every path except the compile-time diagnostic pads with defaults/null (see repro: 6 of 7 cases print a value).

    Compile time (when provable). If the callee resolves statically and the argument count is known, report it. Direct calls already get error: too few arguments to two(): 1 passed, at least 2 expected from analyze, but compile still emits a binary that returns 1: the error is not fatal and the call site does not throw.

    Policy for the static layer (to decide in the fix):

    • user code being compiled as the main program: fatal error (like --analyze-strict);
    • vendor/composer code: warning + a call site that throws ArgumentCountError at run time, never a build failure. Third-party code routinely contains unreachable bad calls (this repo already hit it: Symfony's JsonDescriptor::writeData($service::class), HttpException::fromStatusCode LSB clones), and Zend only fails if the branch runs. Same rule as the provable-argument-type-mismatch handling in TypeCheck (fix/symfony-ownflow-inference, 376cdd7).

    The runtime half is the substance; the static half is a diagnostic on top of it and must not replace it.

  3. added 4 commits that reference this issue on Oct 12, 2026
    d71ea83
    27a37db
    d8c0465
    7f2be54
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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions