Can PHP instantiate an object from the name of the class as a string?
Yes it is:
<?php
$type = 'cc';
$obj = new $type; // outputs "hi!"
class cc {
function __construct() {
echo 'hi!';
}
}
?>
if your class need arguments you should do this:
class Foo
{
public function __construct($bar)
{
echo $bar;
}
}
$name = 'Foo';
$args = 'bar';
$ref = new ReflectionClass($name);
$obj = $ref->newInstanceArgs(array($args));
Yep, definitely.
$className = 'MyClass';
$object = new $className;