Is it possible to dynamically instantiate a class using a variable? For example is something like this possible in PHP?
class foo
{
public $something;
}
$class_name = "foo";
$f = new $class_name();
Is it possible to dynamically instantiate a class using a variable? For example is something like this possible in PHP?
class foo
{
public $something;
}
$class_name = "foo";
$f = new $class_name();
That should work, yes.
You can also do:
Yes you can, your code should work fine.
Yes of course you can instantiate using dynamic names;
Yes, this code will work fine.