note 55304 deleted from language.oop by felipe
| From: | felipe@php.net | Date: | Wed, 23 Apr 2008 11:33:14 +0000 |
| Subject: | note 55304 deleted from language.oop by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138685@lists.php.net to get a copy of this message | ||
Note Submitter: Menno Vanderlist
----
Using the extends statement with classes works, but it did the reverse of what I wanted. I want a
modules hiearchy that adds a module into the main module. So I tried the following, after not
finding anyone else who has done it, and it worked :)
<?php
class subClassA
{ //subClassA
function out()
{ //subClassA::outA()
echo "testing subClassA\n";
}
}
class subClassB
{ //subClassB
function out()
{ //subClassB::outB()
echo "testing subClassB\n";
}
}
class mainClass
{ //mainClass
var $module;
function mainClass($loadModule)
{ // load modules
eval("\$this->module = new $loadModule;");
}
function out()
{ //print out of loaded module
$this->module->out();
}
}
$mainA=new mainClass('subClassA');
$mainA->out();
$mainB=new mainClass('subClassB');
$mainB->out();
?>
outputs:
testing subClassA
testing subClassB