views:

64

answers:

4

For example is something like this possible in PHP?

class foo
{
    public $something;
}

$class_name = "foo";

$f = new $class_name;
+3  A: 

Yes, works fine.

Was it really easier to ask this here than to just test it?

timdev
thank you all for your intelligent responses. It didn't work for me in a slightly different situation. I suppose I should've tested the exact same thing before posting, although an internet search for this didn't turn up anything useful - and now should :)
audio.zoom
A: 

That should work, yes.

You can also do:

$f = new $class($arg1,$arg2);
Chris Kloberdanz
A: 
Sarfraz
+1  A: 

Yes of course you can instantiate using dynamic names;

Muneer