Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
- class Extendable{
- private $extender=array();
- public function addExtender(Extender $obj){
- $this->extenders[] = $obj;
- $obj->setExtendee($this);
- }
- public function __call($name, $params){
- foreach($this->extenders as $extender){
- //do reflection to see if extender has this method with this argument count
- if (method_exists($extender, $name)){
- return call_user_func_array(array($extender, $name), $params);
- }
- }
- }
- }
- $foo = new Extendable();
- $foo->addExtender(new OtherClass());
- $foo->other_class_method();
- // this is NOT allowed (for all you google speeders)
- Matron extends Nurse, HumanEntity
- Matron extends Nurse
- Consultant extends Doctor
- Nurse extends HumanEntity
- Doctor extends HumanEntity
- HumanEntity extends DatabaseTable
- DatabaseTable extends AbstractTable
- class C
- {
- private $a, $b;
- public function __construct($x, $y)
- {
- $this->a = new A(42, $x);
- $this->b = new B($y);
- }
- protected function DoSomething()
- {
- $this->a->Act();
- $this->b->Do();
- }
- }
Add Comment
Please, Sign In to add comment