PHP进行动态装载类
class a{
public function __construct(){
echo "你使用了A类";
}
}
class b{
public function __construct(){
echo "你使用了B类";
}
}
class createCls{
private $obj;
public function __construct($clsName){
try
{
throw new Exception($err);
$this->obj = new $clsName();
}
catch(Exception $e)
{
echo "你装载的类{$clsName}不存在。";
exit();
}
}
}
$a = new createCls(a);
$b = new createCls(b);