Skip to content

ReflectionMethod::invoke and getClosure throw "not invokable" for a method with a variadic or by-reference parameter. #171

Closed

Description

@blacktrs

Summary

ReflectionMethod::invoke and getClosure throw "not invokable" for a method with a variadic or by-reference parameter.

Repro

<?php
class Sum
{
    public function add(int $x, int ...$more): int { return $x + array_sum($more); }
    public function push(array &$into, int $v): void { $into[] = $v; }
}
$m = new ReflectionMethod(Sum::class, 'add');
echo $m->invoke(new Sum(), 1, 2, 3), "\n";
echo $m->getClosure(new Sum())(1, 2, 3), "\n";
$a = [];
(new ReflectionMethod(Sum::class, 'push'))->invokeArgs(new Sum(), [&$a, 5]);
echo count($a), "\n";

Expected (php)

6
6
1

Actual (manticore fb2ec778, Darwin arm64)


[exit code 255]
PHP Fatal error:  Uncaught ReflectionException: Method add is not invokable

Tracking

Known-bug repro: tests/aot/repro/wrong/reflection_invoke_variadic_method.php — bash tests/aot/xfail.sh -k reflection_invoke_variadic_method 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 10, 2026
  2. added
    area:refs
    on Oct 13, 2026
  3. blacktrs commented on Oct 13, 2026

    @blacktrs
    ContributorAuthor

    Partial. The variadic half already works. The by-ref half is open: passing $a[i] as a by-ref arg when the array element is already a ref cell crashes (SIGSEGV in __mir_array_set_int) in plain user code too, so a reflection trampoline fix only turns the 'not invokable' exception into a crash (tried and reverted). Fix the plain-user-code crash first, then the trampoline.

  4. added a commit that references this issue on Oct 14, 2026
    f487dd8
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:refsbugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions