Skip to content

Instantly share code, notes, and snippets.

@andizer
Last active May 26, 2020 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andizer/03fff4e9f11a132c0dbb to your computer and use it in GitHub Desktop.
Save andizer/03fff4e9f11a132c0dbb to your computer and use it in GitHub Desktop.
This example forwards class functionality to the given class
<?php
class Bla {
private static $TargetClass = 'Foo';
public function __callStatic($Method, $Args = array()) {
self::CallMethod($Method, $Args);
}
public function __call($Method, $Args = array()) {
self::CallMethod($Method, $Args);
}
private static function CallMethod($Method, $Args) {
call_user_func_array(
array(self::$TargetClass, $Method),
$Args
);
}
}
class Foo {
public static function Bar() {
echo 123;
}
public function Baz() {
echo 321;
}
}
Bla::Bar();
$Baz = new Bla();
$Baz->Baz();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment