CKTIS / PHP
__callStatic
De openbare statische methode `__callStatic` vangt statische aanroepen van ontbrekende of ontoegankelijke methoden op.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
public static function __callStatic(string $name, array $arguments): mixedDe openbare statische methode __callStatic vangt statische aanroepen van ontbrekende of ontoegankelijke methoden op. Ze ontvangt de naam en de argumenten met hun benoemde sleutels. Bij overerving geeft static::class de aangeroepen klasse en is er geen instantie aan $this gekoppeld.
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}]]
Voorbeelden
<?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)]);
Resultaat
["regular",["CrateFactory","Make",{"code":4}]]