Open MauricioFauth opened 3 months ago
The magic methods __call and __callStatic requires exactly two parameters, otherwise a fatal error will occur.
__call
__callStatic
So, both $name and $arguments are required parameters, even if they are not used inside the method.
$name
$arguments
<?php declare(strict_types=1); /** * @method string foo() * @method static string bar() */ final class MethodTest { /** @param mixed[] $arguments */ public function __call(string $name, array $arguments): mixed { return match ($name) { 'foo' => 'foo', default => throw new RuntimeException(), }; } /** @param mixed[] $arguments */ public static function __callStatic(string $name, array $arguments): mixed { return match ($name) { 'bar' => 'bar', default => throw new RuntimeException(), }; } } $obj = new MethodTest(); echo $obj->foo(); echo $obj::bar(); echo MethodTest::bar();
https://3v4l.org/3P1cM
foobarbar
https://3v4l.org/H55oa
- public function __call(string $name, array $arguments): mixed + public function __call(string $name): mixed
Fatal error: Method MethodTest::__call() must take exactly 2 arguments in /in/H55oa on line 10
https://3v4l.org/XLoWr
- public static function __callStatic(string $name, array $arguments): mixed + public static function __callStatic(string $name): mixed
Fatal error: Method MethodTest::__callStatic() must take exactly 2 arguments in /in/XLoWr on line 19
https://psalm.dev/r/1c112dae46
I found these snippets:
The magic methods
__call
and__callStatic
requires exactly two parameters, otherwise a fatal error will occur.So, both
$name
and$arguments
are required parameters, even if they are not used inside the method.https://3v4l.org/3P1cM
https://3v4l.org/H55oa
https://3v4l.org/XLoWr
https://psalm.dev/r/1c112dae46