Last active
May 26, 2020 08:40
-
-
Save andizer/03fff4e9f11a132c0dbb to your computer and use it in GitHub Desktop.
This example forwards class functionality to the given class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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