Using __callStatic()
The __callStatic()
magic is nearly identical to the __call()
method. Where the __call()
method is bound to the object context, the __callStatic()
 method is bound to the static context, which means this method is triggered when invoking inaccessible methods via the scope resolution operator (::
).
The method accepts two parameters as per the following synopsis:
public static mixed __callStatic (string $name, array $arguments)
Notice the use of the static access modifier in the method declaration that is required by the static context upon which this method operates. The following example demonstrates the use of the __callStatic()
method in the static context:
<?php class User { public static function __callStatic($name, $arguments) { echo '__callStatic => ' . $name . ': ' . implode(', ', $arguments) . PHP_EOL; } public static function bonus($amount) { echo 'bonus: ' . $amount . PHP_EOL; } }
code will yield the following output:
User::hello('John...