views:

58

answers:

1

Hi,

I want to do something like this: (in php)


$a = "class_name1";

$b = "class_name2";

$object1 = new $a;

$object2 = new $b

is this possible?

thank you very much for your time

+5  A: 

Yes:

class A {
   public function foo(){
       echo 'bar';
   } 
}

$a = 'A';
$object = new $a();
$object->foo();

outputs

bar

You can test such things by yourself very fast on codepad.

Felix Kling