Re: help with some class problem
| From: | Remy Dufour | Date: | Wed, 19 Jun 2002 13:23:12 +0000 |
| Subject: | Re: help with some class problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-102924@lists.php.net to get a copy of this message | ||
I've already done this and it work fine:
class Main
{
function loadmod($name,&$mod)
{
$mod = new $name; // load module
// You implement this function in all your modules
$mod->setMainClass(& $this);
}
}
class testmodule
{
var $mainClass;
// The function
function setMainClass(& $obj)
{
$this->mainClass = & $obj;
}
}
$main->loadmod('testmodule',$m);
// To acces main class property...
$m->mainClass->mainProperty
----- Original Message -----
From: "Uros Gruber" <uros.gruber@sir-mag.com>
To: <php-general@lists.php.net>
Sent: Wednesday, June 19, 2002 4:42 AM
Subject: [PHP] help with some class problem
> Hi!
>
> i'm making some modular aplication. I have one base class for
> example:
>
> class Main {
>
> function loadmod($name,&$mod) {
> $mod = new $name; // load module
> }
> }
>
> In module class i want to use some properties from main
> module, but i don't know how to solve this. But i don't want
> extend all module from main class,
>
> i call modules like this.
>
> first i initialize main class
>
> $main = new Main;
> $main->loadmod('testmodule',$m);
>
> and when i wan't to call some function from it i call
>
> $m->modulFunction(arg);
>
> i also don't know if this is right way to do this, but my
> point is that i want to have some main class on wich i buld
> modules, this modules use some properties en methods from
> main class like dbacces, configuration ....
>
>
> And also i don't want this to be slower everytime i add ne
> module.
>
> any ideas