如果文件具有相同的名称,但类不具有相同的名称,则class_exists返回true

时间:2018-09-27 05:54:05

标签: php

有一个名为file的PHP RefGererCauseRiskView.php;在该文件内有class的声明和定义:

<?php
class C_RefGererCauseRiskView extends View {
   ...
}
?>

在运行时,以下语句返回true:if (class_exists('RefGererCauseRiskView'))

那怎么了?

编辑:

框架mvc:

index.php:

<?php

$action_factory =& new ActionFactory() ;
$action_factory->getAction(true) ;
$action_factory->execute() ;

?>

ActionFactory:

<?php

class Action {
    function Action() {}
    function execute() {}
}

class ActionResult {
    var $mapping;
    var $data;

    function ActionResult($mapping, $data) {
        $this->mapping = $mapping;
        $this->data = $data;
    }

    function getViewMapping() {return $this->mapping;}
    function getResultData() {return $this->data;}
}

class View {
    function View() {}
    function processView($data) {}
}

class ActionFactory {

    var $action_class = null ;

    function ActionFactory () {}

    function getAction() {

        define('ACTION', isset($_REQUEST['action']) ? $_REQUEST['action'] : 'Main');

        $relative_path = trim(relative_path());

        $dir_actions = "";
        if ($relative_path != "index.php" && $relative_path != "mp.php") {
            $tab_action = explode(".", $relative_path);
            $dir_actions = $tab_action[0]."/";
        }
        $action_class = ACTION.'Action' ;

        if ( !class_exists($action_class, false) ) {
            $file_actions = RP_ACTIONS.$dir_actions.$action_class.'.php';
            if ( file_exists($file_actions)) {
                require_once $file_actions ;
            } else {
                die($file_actions . " !");
            }
        }
        $this->action_class =& new $action_class() ;
    }

    function execute() {
        $action_result = $this->action_class->execute();
        $view_factory =& new ViewFactory() ;
        $view = $view_factory->getView() ;
        $view->processView($action_result);
    }

}

class ViewFactory {

    function ViewFactory() {}

    function getView() {

        $view_class   = (isset($_REQUEST['action'])?$_REQUEST['action']:'Main').'View' ;

        $relative_path = relative_path();

        $dir_views = "";
        if ($relative_path != "index.php" && $relative_path != "mp.php") {
            $tab_action = explode(".", $relative_path);
            $dir_views = $tab_action[0]."/";
        }
        $action_class = ACTION.'View' ;

        if ( !class_exists($view_class, false) ) {
            $file_views = RP_VIEWS.$dir_views.$action_class.'.php';
            if ( file_exists($file_views)) {
                require_once $file_views ;
            } else {
                die($file_views . " !");
            }
        }
        return new $view_class();
    }
}

?>

0 个答案:

没有答案
相关问题