PHP无法重新声明由函数引起的类

时间:2015-11-24 08:59:40

标签: php function class oop redeclare

我得到了一个无法重新声明类错误。这是导致错误的类文件

<?
class siteLoader{


public $view;
protected $page;
//vars for render head function
protected $arraySize;
protected $counter;

public function __construct(){}
//renders the view for the site
public function renderView($view){
    $this->view = $view;
    return "view/{$view}.view.php";
}
//renders the head part of the site
//public function renderHead($head){
public function renderHead($charset,$title,$description,$keywords,$applicationName,$css){
    //$this->head = $head;
    $this->charset = $charset;
    $this->title = $title;
    $this->description = $description;
    $this->keywords = $keywords;
    $this->applicationName = $applicationName;
    $this->css = $css;
    $arraySize = count($this->css, COUNT_RECURSIVE);
    $counter =0;
    echo '<head>
        <meta charset="'.$charset.'">
        <meta application-name="'.$applicationName.'">
        <meta keywords="'.$keywords.'">
        <meta description="'.$description.'">
        <title>'.$title.'</title>
    ';
    do{
        echo '<link type="text/css" rel="stylesheet" href="css/'.$this->css[$counter].'.css">';
        $counter++;
        }while($counter != $arraySize);
    echo '</head>';
    return 0;
}


}
?>

只有当我调用renderView()函数时才会发生错误。 下面是我调用类和函数的索引。

<!DOCTYPE html>
<html>
<?
if(!class_exists('siteLoader'))
{
require_once('/classes/html.class.php');
}

//$head = new html;
$html = new siteLoader;
$viewrender = new siteLoader;

$charset = "utf-8";
$title = "musicDB";
$description = "Not made yet";
$keywords = "music,DB,rock,Database,etc";
$applicationName = "Music DataBase";
$css = array('style');
$view = "main";
     $html->renderHead($charset,$title,$description,$keywords,$applicationName,$css);
include $viewrender->renderView($view);

?>
</html>

如上所示,我使用require_once并检查该类是否已加载。 问题可能出在renderView函数中,因为当我不使用该函数时,一切正常。

1 个答案:

答案 0 :(得分:0)

这行包括$ viewrender-&gt; renderView($ view); main.view.php中类的名称是什么,查看类名是否为siteloader