foo = self::foo($object); $object->bar = self::bar($object); } public static function foo($object) { return function() use ($object){ return 'fooshizzle'; }; } public static function bar($object) { return function() use ($object){ return 'barrrtastic'; }; } } class SomeClass { public function __construct() { SomeModule::append($this); } public function __call($method, $args) { if(!property_exists($this, $method)) { throw new \BadFunctionCallException("Call to undefined method SomeClass::$method()"); } $closure = $this->$method; return call_user_func_array($closure, $args); } } $object = new SomeClass(); var_dump($object->foo()); //string(10) "fooshizzle" class NerdyCoolnessPrinter { public function foo() { return 'fooshizzle'; } public function bar() { return 'barrrtastic'; } } class SomeOtherClass { private $_coolnessPrinter; public function __construct() { $this->_coolnessPrinter = new NerdyCoolnessPrinter(); } public function foo() { return $this->_coolnessPrinter->foo(); } public function bar() { return $this->_coolnessPrinter->bar(); } } class ElisUrlViewHelper { private $_baseUrl; private $_jsFunc; public function __construct($baseurl, $jsfunc) { $this->_baseUrl = $baseurl; $this->_jsFunc = $jsfunc; } public function __invoke($p) { if($this->_jsFunc) { return "javascript:{$this->_jsFunc}({$p})"; } elseif($this->_baseUrl) { return "{$this->_baseUrl}/page/$p"; } } } $urlHelper = new ElisUrlViewHelper('http://johnkleijn.nl', false); $page = 10; ?> ← Previous _host = $host; } public function setPath($path) { $this->_path = $path; return $this; } public function __invoke($path) { return $this->setPath($path); } public function __toString() { return "{$this->_host}{$this->_path}"; } } $www = new Crimson_Url_Absolute('http://www.example.com'); $ssl = new Crimson_Url_Absolute('https://www.example.com'); echo $www('/foo.jpg') . PHP_EOL; echo $ssl('/secure.php') . PHP_EOL; try { $object->meh(); } catch(\BadFunctionCallException $e) { echo "meh() not supported"; }