Last active
December 12, 2015 03:18
-
-
Save tatat/4705644 to your computer and use it in GitHub Desktop.
This file contains 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 Nyan { | |
static public function static_method_nyan() { | |
echo 'static nyan', "\n"; | |
} | |
static public function __callStatic($name, $args) { | |
$method_name = 'static_method_' . $name; | |
if (method_exists(__CLASS__, $method_name)) { | |
return call_user_func_array(array(__CLASS__, $method_name), $args); | |
} else { | |
trigger_error('Call to undefined method ' . __CLASS__ . "::{$name}()", E_USER_ERROR); | |
} | |
} | |
public function instance_method_nyan() { | |
echo 'instance nyan', "\n"; | |
} | |
public function __call($name, $args) { | |
$method_name = 'instance_method_' . $name; | |
if (method_exists($this, $method_name)) { | |
return call_user_func_array(array($this, $method_name), $args); | |
} else { | |
trigger_error('Call to undefined method ' . __CLASS__ . "::{$name}()", E_USER_ERROR); | |
} | |
} | |
} |
This file contains 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 | |
Nyan::nyan(); #=> static nyan | |
$nyan = new Nyan(); | |
$nyan->nyan(); #=> instance nyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment