Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Plugin system: Automatically instantiate included classes?

 
   Database Forums (Home) -> PHP RSS
Next:  problems with login script  
Author Message
Arne-Kolja Bachstein

External


Since: May 19, 2008
Posts: 2



(Msg. 1) Posted: Mon May 19, 2008 11:55 am
Post subject: Plugin system: Automatically instantiate included classes?
Archived from groups: comp>lang>php (more info?)

Hi there,

I am planning to implement a plugin system, based on the observer
pattern in some way, but now I am stuck with the instantiation of the
plugins.

I want the plugins to have their own class, abstracted from the class
Plugin. So far its nothing new. But how could I possibly automate the
instantiation of the included plugin, without knowing it/hardcoding
it? I'd like to have an array of activated plugins and based on this I
have to instantiate them to give them to the observed object. But I
dont know how to instantiate a class just by its name in a variable
without using eval() or something (dont like eval()).

Does anybody know how to solve this?

Best regards,

Arne

 >> Stay informed about: Plugin system: Automatically instantiate included classes? 
Back to top
Login to vote
Arne-Kolja Bachstein

External


Since: May 19, 2008
Posts: 2



(Msg. 2) Posted: Mon May 19, 2008 12:01 pm
Post subject: Re: Plugin system: Automatically instantiate included classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 19 Mai, 20:58, Michael Fesser wrote:
> .oO(Arne-Kolja Bachstein)
>
> >I am planning to implement a plugin system, based on the observer
> >pattern in some way, but now I am stuck with the instantiation of the
> >plugins.
>
> >I want the plugins to have their own class, abstracted from the class
> >Plugin. So far its nothing new. But how could I possibly automate the
> >instantiation of the included plugin, without knowing it/hardcoding
> >it? I'd like to have an array of activated plugins and based on this I
> >have to instantiate them to give them to the observed object. But I
> >dont know how to instantiate a class just by its name in a variable
> >without using eval() or something (dont like eval()).
>
> >Does anybody know how to solve this?
>
> $foo = 'yourClass';
> $bar = new $foo();
>
> Micha

that does work? i'm embarrassed Smile thank you Smile

 >> Stay informed about: Plugin system: Automatically instantiate included classes? 
Back to top
Login to vote
Michael Fesser

External


Since: Mar 01, 2006
Posts: 315



(Msg. 3) Posted: Mon May 19, 2008 8:58 pm
Post subject: Re: Plugin system: Automatically instantiate included classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(Arne-Kolja Bachstein)

>I am planning to implement a plugin system, based on the observer
>pattern in some way, but now I am stuck with the instantiation of the
>plugins.
>
>I want the plugins to have their own class, abstracted from the class
>Plugin. So far its nothing new. But how could I possibly automate the
>instantiation of the included plugin, without knowing it/hardcoding
>it? I'd like to have an array of activated plugins and based on this I
>have to instantiate them to give them to the observed object. But I
>dont know how to instantiate a class just by its name in a variable
>without using eval() or something (dont like eval()).
>
>Does anybody know how to solve this?

$foo = 'yourClass';
$bar = new $foo();

Micha
 >> Stay informed about: Plugin system: Automatically instantiate included classes? 
Back to top
Login to vote
Iván_Sánchez_Ortega

External


Since: Oct 12, 2005
Posts: 45



(Msg. 4) Posted: Mon May 19, 2008 9:05 pm
Post subject: Re: Plugin system: Automatically instantiate included classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Arne-Kolja Bachstein wrote:

> But I dont know how to instantiate a class just by its name in a variable
> without using eval() or something (dont like eval()).

__autoload() ??

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Proudly running Debian Linux with 2.6.24-1-amd64 kernel, KDE 3.5.9, and PHP
5.2.6-1 generating this signature.
Uptime: 21:04:11 up 19 days, 24 min, 5 users, load average: 0.35, 0.59,
0.68
 >> Stay informed about: Plugin system: Automatically instantiate included classes? 
Back to top
Login to vote
Michael Fesser

External


Since: Mar 01, 2006
Posts: 315



(Msg. 5) Posted: Mon May 19, 2008 9:10 pm
Post subject: Re: Plugin system: Automatically instantiate included classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(Arne-Kolja Bachstein)

>On 19 Mai, 20:58, Michael Fesser wrote:
>>
>> >Does anybody know how to solve this?
>>
>> $foo = 'yourClass';
>> $bar = new $foo();
>>
>> Micha
>
>that does work? i'm embarrassed Smile thank you Smile

You're welcome. Wink

Micha
 >> Stay informed about: Plugin system: Automatically instantiate included classes? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Can someone wxplain classes to me please - the why not wha.. - I understand what a class is but am confused as to why so many people are using them for what appear to be very simple PHP applications. I guess I dont know enough about how they are useful. for example I've just seen a "who is" application ...

Symbols used in classes. - Hi all., Probably an old quesion, but im pretty new to php, and have not had great success in searching. Ive looking over some code which contains the following terms $this -> :: And have not clue as to what they mean. I have been looking at the ph...

Best way of calling multiple classes? - I'm designing a small framework with a lot of classes (1 file per class) and want to know the best method of calling each class? Obviously I could I call each file that is used but that could be 10 or more include statements. I am wonering if there is...

Change included code - Can I modify code that I have included using <?php include("../Index.php"); ?> The Index.php file contains links that need to be modified to work. Index.php is basically an html file uses a linked css file and when its included in the...

include files not being included - Hello, I'm running php 5.2.5 installed from ports on a FreeBSD machine with apache2 as the webserver. I've got php set up properly, but it doesn't include include files. If i do a phpinfo() in a file that works telling me php file processing is..
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]