Page 1 of 1

Creating an object based on a variable?

Posted: Sat Jun 03, 2006 11:26 pm
by Flamie
Say I have like:

Code: Select all

$npc_name = "Mayor";
What I want to do is something like this:

Code: Select all

$npc = new $npc_name(); //I wnat this to act as $npc = new Mayor();
So is it doable in someway?

Posted: Sat Jun 03, 2006 11:41 pm
by bdlang
PHP Manual: variable variables

Posted: Sat Jun 03, 2006 11:49 pm
by Flamie
thanks a lot.

Re: Creating an object based on a variable?

Posted: Sun Jun 04, 2006 12:41 am
by Christopher
Flamie wrote:

Code: Select all

$npc_name = "Mayor";
$npc = new $npc_name(); //I wnat this to act as $npc = new Mayor();
So is it doable in someway?
Did you try it before you asked the question?

Re: Creating an object based on a variable?

Posted: Sun Jun 04, 2006 2:44 am
by Oren
arborint wrote:Did you try it before you asked the question?
:P I don't get this kind of posts at all... Couldn't you just try it?