<?php
function foo(int $x, int $a, int $b = 2) {
var_dump($x, $a, $b);
}
$rf = new ReflectionFunction("foo");
$rf->invokeArgs([1 => 0, 0 => 1, "b" => 6]);
class Foo {
public function __construct(int $x, int $a, int $b = 2) {
var_dump($x, $a, $b);
}
public function method(int $x, int $a, int $b = 2) {
var_dump($x, $a, $b);
}
}
$rc = new ReflectionClass(Foo::class);
$instance = $rc->newInstanceArgs([1 => 0, 0 => 1, "b" => 6]);
$rc->getMethod("method")->invokeArgs($instance, [1 => 0, 0 => 1, "b" => 6]);
- Output for 7.4.33, 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
- int(0)
int(1)
int(6)
int(0)
int(1)
int(6)
int(0)
int(1)
int(6)
preferences:
51.19 ms | 406 KiB | 5 Q