Skip to content

An internal function called with more arguments than it accepts returns normally instead of throwing ArgumentCountError. #643

Closed

Description

@blacktrs

Summary

An internal function called with more arguments than it accepts returns normally instead of throwing ArgumentCountError.

Repro

<?php
try {
    var_dump(strlen("a", "b"));
} catch (ArgumentCountError $e) {
    echo get_class($e), ": ", $e->getMessage(), "\n";
}

Expected (php)

ArgumentCountError: strlen() expects exactly 1 argument, 2 given

Actual (manticore 783f6c3c, Darwin arm64)

int(1)

Tracking

Known-bug repro: tests/aot/repro/wrong/internal_fn_surplus_args_no_argcount_error.php — bash tests/aot/xfail.sh -k internal_fn_surplus_args_no_argcount_error 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 Nov 10, 2026
  2. blacktrs commented on Nov 10, 2026

    @blacktrs
    ContributorAuthor

    Tried the direct fix (throw ArgumentCountError at the call site when an internal function gets more arguments than its signature declares). It is blocked: 18 stdlib functions declare FEWER parameters than php, so a php-valid call would start throwing — array_keys (1 vs 3), mkdir (3/4), rmdir (1/2), rename (2/3), copy (2/3), file (2/3), readfile (1/3), hash (3/4), hash_file (3/4), file_get_contents (3/5), file_put_contents (3/4), fopen (2/4), unlink (1/2), opendir (1/2), scandir (2/3), strrchr (2/3), str_word_count (2/3), strspn (3/4). Prelude functions were not audited yet. Order: make those signatures php-faithful (AGENTS.md: keep PHP signatures php-faithful), then add the check (emitCall, php-visible global names, non-variadic; arguments evaluated before the throw).

  3. blacktrs commented on Nov 10, 2026

    @blacktrs
    ContributorAuthor

    Fixed on branch shared-generics: the 17 stdlib and 6 prelude signatures now declare php's parameters, and the call-site check throws php's ArgumentCountError. One exception by the two-step rule: array_keys keeps its one-parameter declaration (the emitter reads its arguments by count; an older compiler fills defaults into that call). The lowering fix that makes adding them safe is in the same commit; add array_keys($array, $filter_value, $strict) after BOOTSTRAP_VERSION is raised past it.

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