Created
February 23, 2019 14:31
-
-
Save BEcraft/7821027e31fd7cbfbcf0536683e5a184 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 A { | |
private $e; | |
public function __construct(){ | |
$this->e = new B(); | |
} | |
public function __call(string $name, array $arguments) { | |
if (!method_exists($this, $name)) { | |
if (method_exists($this->e, $name)) { | |
return $this->e->$name($arguments); | |
} | |
throw new \Error("Call to undefined function \"{$name}()\" (#" . count($arguments) . ")"); | |
} else { | |
return $this->$name($arguments); | |
} | |
} | |
public function e() { | |
return __CLASS__ . " : E"; | |
} | |
} | |
class B { | |
public function f() { | |
return __CLASS__ . " : F"; | |
} | |
} | |
$a = new A(); | |
echo $a->f(); //prints 'B : F' | |
echo $a->z(); //throws error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment