Created
May 16, 2014 13:15
-
-
Save egulhan/4abde2d66dd041b39f0e to your computer and use it in GitHub Desktop.
PHP does not support multiple inheritance. This shows how to make it possible.
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
// Source: http://stackoverflow.com/a/356431 | |
class B { | |
public function method_from_b($s) { | |
echo $s; | |
} | |
} | |
class C { | |
public function method_from_c($s) { | |
echo $s; | |
} | |
} | |
class A extends B | |
{ | |
private $c; | |
public function __construct() | |
{ | |
$this->c = new C; | |
} | |
// fake "extends C" using magic function | |
public function __call($method, $args) | |
{ | |
$this->c->$method($args[0]); | |
} | |
} | |
$a = new A; | |
$a->method_from_b("abc"); | |
$a->method_from_c("def"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@xeoncross, yes you are right. :)