CKTIS / PHP
__callStatic
The public static method `__callStatic` handles a missing or inaccessible method in a static call.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
public static function __callStatic(string $name, array $arguments): mixedThe public static method __callStatic handles a missing or inaccessible method in a static call. It receives the requested spelling and an argument array, with named keys preserved. Use static::class to inspect the called class under inheritance; no instance is bound to $this. Accessible static methods use their own implementation.
class Factory {
public static function known(): string { return "regular"; }
public static function __callStatic(string $name, array $arguments): mixed {
return [static::class, $name, $arguments];
}
}
class CrateFactory extends Factory {}
echo json_encode([CrateFactory::known(), CrateFactory::Make(code: 4)]);
["regular",["CrateFactory","Make",{"code":4}]]
Examples
<?php
class Factory {
public static function known(): string { return "regular"; }
public static function __callStatic(string $name, array $arguments): mixed {
return [static::class, $name, $arguments];
}
}
class CrateFactory extends Factory {}
echo json_encode([CrateFactory::known(), CrateFactory::Make(code: 4)]);
Result
["regular",["CrateFactory","Make",{"code":4}]]