- 论坛徽章:
- 0
|
看来有悬赏的帖子回答就是踊跃.我也凑凑热闹
LZ可以看看PHP实现 工厂模式
这里是我的一段正在运行中的代码
class fu
{
.............
function build($class_name,$param=null)
{
$f_path =PATH_INCLUDE.$class_name.EXT;
if($this->_is_exist(PATH_INCLUDE,$class_name.EXT))
{
if(!@is_object($this->$class_name))
{
require($f_path);
$str = '$this->$class_name =new $class_name(';
if (is_array($param)) {
foreach ($param as $key)
{
if (!empty($key)) {
$str .= '\''.$key.'\',';
}
}
$str = substr($str, 0, -1);
}
$str .= ');';
eval($str);
$this->obj[$class_name] =&$this->$class_name;
$this->$class_name->fu = &$this;
if (method_exists($this->$class_name,'init')) {
$this->$class_name->init();
}
}
return $this->$class_name;
}
else
{
$this->fatal_error('file:'.$f_path.' not found!<BR>');
}
} |
|
|