Skip to content

Instantly share code, notes, and snippets.

@tatat
Last active December 12, 2015 03:18
Show Gist options
  • Save tatat/4705644 to your computer and use it in GitHub Desktop.
Save tatat/4705644 to your computer and use it in GitHub Desktop.
<?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);
}
}
}
<?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