Jump to content

Recommended Posts

Hello guys!

 

I have a probably simple question for you...

 

Let's say I have these two classes:

class core
{
   function core()
   {
      //do stuff here
   }
}

class parser extends core
{
   function parser()
   {
      //do other stuff here
   }
}

 

Can I somehow tell the "core" class when it runs the constructor to load inside it (parent) all available extender classes?

So if someone writes a new class to extend the "core" it should be automatically loaded, without needing me to load it in the constructor of the parent or to initialize with:

$sub = new $subclassX;

 

 

I am looking into something like adding a few classes that I need into the "core" class, but more if I have let's say a function "getID()" in the "core" and someone wants to use a different method, to easy load a new class with a new function that will do it the new way. Is this possible?

 

 

Thank you for any help.

Boby

Link to comment
https://forums.phpfreaks.com/topic/71055-autoload-extender-classes/
Share on other sites

you want to call functions and variables from the parent class in the child class without initiating the parent class?  If so, you can do stuff like:

 

parent::core();

parent::function();

 

get what i'm saying?  http://us2.php.net/manual/en/language.oop5.paamayim-nekudotayim.php  I think that might help

Or if not then you basically answered your own question.

in the constructor you would just instantiate each extension into

a variable and you can have access to it that way.

Look at cake/code ignitor because they have a nice way of doing it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.