469,645 Members | 1,360 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Plugin system: Automatically instantiate included classes?

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
Jun 2 '08 #1
4 1912
..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
Jun 2 '08 #2
On 19 Mai, 20:58, Michael Fesser <neti...@gmx.dewrote:
.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 :-) thank you :-)
Jun 2 '08 #3
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

Jun 2 '08 #4
..oO(Arne-Kolja Bachstein)
>On 19 Mai, 20:58, Michael Fesser <neti...@gmx.dewrote:
>>
>Does anybody know how to solve this?

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

Micha

that does work? i'm embarrassed :-) thank you :-)
You're welcome. ;)

Micha
Jun 2 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Bob | last post: by
7 posts views Thread by Reinhold Birkenfeld | last post: by
2 posts views Thread by Rudolf | last post: by
3 posts views Thread by Roger Boesch | last post: by
2 posts views Thread by Matt | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.