Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 后期静态绑定问题_Php_Late Static Binding - Fatal编程技术网

Php 后期静态绑定问题

Php 后期静态绑定问题,php,late-static-binding,Php,Late Static Binding,我在自己的项目中遇到了一些麻烦。我正在编写一个简单的考试系统,为了方便起见,我使用了后期静态绑定。我有下一个代码: <?php class Controler { public $dir; public $name; public $file; public function __construct( $dir = ST_CONTROL_DIR ) { $this->dir = $dir; } public func

我在自己的项目中遇到了一些麻烦。我正在编写一个简单的考试系统,为了方便起见,我使用了后期静态绑定。我有下一个代码:

<?php
class Controler {
    public $dir;
    public $name;
    public $file;

    public function __construct( $dir = ST_CONTROL_DIR ) {
        $this->dir = $dir;
    }

    public function __call( $name, $arguments = array() ) {
        $this->name = &$name;
        $this->file = $this->dir . $this->name . '.php';

        var_dump(get_called_class());

        $result = $this->controler_include( ... $arguments );
        return $result;
    }
    public static function __callStatic( $name, $arguments = array() ) {
        var_dump(get_called_class());
        $obj = new static();
        return $obj->$name( ... $arguments );
    }
    private final function controler_include(){
        return include $this->file;
    }
}

class Router extends Controler {
    public function __construct(){
        parent::__construct(ST_ROUTER_DIR);
    }
}


class Routing {
    protected $action;
    protected $params;
    protected $reffer;

    static public function initialize(){
        global $ROUTER;
        $ROUTER = new self;
    }
    static public function process(){
        global $ROUTER;
        xdebug_start_trace( ST_DIR.'trace' );
        if($ROUTER->action == 'api'){
            $ROUTER->action = array_shift( $ROUTER->params );
            trig( 'router_process_api_before' );
            return Api::{ $ROUTER->action }( ... $ROUTER->params );
        } else {
            trig( 'router_process_before' );
            return Router::{$ROUTER->action}( ... $ROUTER->params );
        }
        xdebug_stop_trace();
    }
}
XDebug跟踪:

TRACE START [2017-01-17 00:19:00]
    0.0292     414792         -> trig('router_process_before') /public_html/vendor/core/Routing.php:40
    0.0293     414888           -> func_get_args() /public_html/vendor/core/Core.php:87
                                 >=> array (0 => 'router_process_before')
    0.0293     414936           -> Core->trig($name = 'router_process_before') /public_html/vendor/core/Core.php:87
    0.0293     414984             -> func_get_args() /public_html/vendor/core/Core.php:58
                                   >=> array (0 => 'router_process_before')
    0.0293     415288             -> array_shift(array (0 => 'router_process_before')) /public_html/vendor/core/Core.php:59
                                   >=> 'router_process_before'
    0.0294     415200             -> func_num_args() /public_html/vendor/core/Core.php:61
                                   >=> 1
                                 >=> NULL
                               >=> NULL
    0.0294     415008         -> Router::login() /public_html/vendor/core/Routing.php:41
    0.0295     415192           -> Controler::__callStatic($name = 'login', $arguments = array ()) /public_html/vendor/core/Routing.php:41
    0.0295     415376             -> Router->__construct() /public_html/vendor/core/Controler.php:44
    0.0295     415544               -> Controler->__construct($dir = '/public_html/vendor/router/') /public_html/vendor/core/Routing.php:77
                                     >=> NULL
                                   >=> NULL
    0.0295     415712             -> Router->login() /public_html/vendor/core/Controler.php:45
    0.0296     416072               -> Controler->__call($name = 'login', $arguments = array ()) /public_html/vendor/core/Controler.php:45
    0.0296     416344                 -> get_called_class() /public_html/vendor/core/Controler.php:25
                                       >=> 'Router'
    0.0296     416424                 -> var_dump('Router') /public_html/vendor/core/Controler.php:25
                                       >=> NULL
    0.0297     416344                 -> file_exists('/public_html/vendor/router/login.php') /public_html/vendor/core/Controler.php:33
                                       >=> TRUE
    0.0297     416328                 -> Controler->controler_include() /public_html/vendor/core/Controler.php:38
    0.0299     420376                   -> include(/public_html/vendor/router/login.php) /public_html/vendor/core/Controler.php:48
    0.0300     420784                     -> reg('view_header_css', class Closure {  }) /public_html/vendor/router/login.php:4
    0.0300     420968                       -> func_get_args() /public_html/vendor/core/Core.php:86
                                             >=> array (0 => 'view_header_css', 1 => class Closure {  })
    0.0300     420920                       -> Core->reg($name = 'view_header_css', $callback = class Closure {  }, $order = ???) /public_html/vendor/core/Core.php:86
    0.0301     421016                         -> is_null(NULL) /public_html/vendor/core/Core.php:45
                                               >=> TRUE
                                             >=> NULL
                                           >=> NULL
    0.0301     421384                     -> Controler->message() /public_html/vendor/router/login.php:7
    0.0302     421568                       -> Controler->__call($name = 'message', $arguments = array ()) /public_html/vendor/router/login.php:7
    0.0302     421696                         -> get_called_class() /public_html/vendor/core/Controler.php:25
                                               >=> 'Router'
    0.0302     421776                         -> var_dump('Router') /public_html/vendor/core/Controler.php:25
                                               >=> NULL
    0.0302     421696                         -> file_exists('/public_html/vendor/router/message.php') /public_html/vendor/core/Controler.php:33
                                               >=> FALSE
    0.0304     438336                         -> EControlerNotFound->__construct($object = class Router { public $dir = '/public_html/vendor/router/'; public $name = 'message'; public $file = '/public_html/vendor/router/message.php' }, $name = 'message', $file = '/public_html/vendor/router/message.php') /public_html/vendor/core/Controler.php:35
    0.0308      19352
TRACE END   [2017-01-17 00:19:00]
如果我调用View::{'message'}-好的。(视图是控制器的子级)

现在我的问题是:当我调用父类的静态方法时,有人能解释为什么PHP执行子类的非静态方法吗

string 'Router' (length=6)
string 'Router' (length=6)
TRACE START [2017-01-17 00:19:00]
    0.0292     414792         -> trig('router_process_before') /public_html/vendor/core/Routing.php:40
    0.0293     414888           -> func_get_args() /public_html/vendor/core/Core.php:87
                                 >=> array (0 => 'router_process_before')
    0.0293     414936           -> Core->trig($name = 'router_process_before') /public_html/vendor/core/Core.php:87
    0.0293     414984             -> func_get_args() /public_html/vendor/core/Core.php:58
                                   >=> array (0 => 'router_process_before')
    0.0293     415288             -> array_shift(array (0 => 'router_process_before')) /public_html/vendor/core/Core.php:59
                                   >=> 'router_process_before'
    0.0294     415200             -> func_num_args() /public_html/vendor/core/Core.php:61
                                   >=> 1
                                 >=> NULL
                               >=> NULL
    0.0294     415008         -> Router::login() /public_html/vendor/core/Routing.php:41
    0.0295     415192           -> Controler::__callStatic($name = 'login', $arguments = array ()) /public_html/vendor/core/Routing.php:41
    0.0295     415376             -> Router->__construct() /public_html/vendor/core/Controler.php:44
    0.0295     415544               -> Controler->__construct($dir = '/public_html/vendor/router/') /public_html/vendor/core/Routing.php:77
                                     >=> NULL
                                   >=> NULL
    0.0295     415712             -> Router->login() /public_html/vendor/core/Controler.php:45
    0.0296     416072               -> Controler->__call($name = 'login', $arguments = array ()) /public_html/vendor/core/Controler.php:45
    0.0296     416344                 -> get_called_class() /public_html/vendor/core/Controler.php:25
                                       >=> 'Router'
    0.0296     416424                 -> var_dump('Router') /public_html/vendor/core/Controler.php:25
                                       >=> NULL
    0.0297     416344                 -> file_exists('/public_html/vendor/router/login.php') /public_html/vendor/core/Controler.php:33
                                       >=> TRUE
    0.0297     416328                 -> Controler->controler_include() /public_html/vendor/core/Controler.php:38
    0.0299     420376                   -> include(/public_html/vendor/router/login.php) /public_html/vendor/core/Controler.php:48
    0.0300     420784                     -> reg('view_header_css', class Closure {  }) /public_html/vendor/router/login.php:4
    0.0300     420968                       -> func_get_args() /public_html/vendor/core/Core.php:86
                                             >=> array (0 => 'view_header_css', 1 => class Closure {  })
    0.0300     420920                       -> Core->reg($name = 'view_header_css', $callback = class Closure {  }, $order = ???) /public_html/vendor/core/Core.php:86
    0.0301     421016                         -> is_null(NULL) /public_html/vendor/core/Core.php:45
                                               >=> TRUE
                                             >=> NULL
                                           >=> NULL
    0.0301     421384                     -> Controler->message() /public_html/vendor/router/login.php:7
    0.0302     421568                       -> Controler->__call($name = 'message', $arguments = array ()) /public_html/vendor/router/login.php:7
    0.0302     421696                         -> get_called_class() /public_html/vendor/core/Controler.php:25
                                               >=> 'Router'
    0.0302     421776                         -> var_dump('Router') /public_html/vendor/core/Controler.php:25
                                               >=> NULL
    0.0302     421696                         -> file_exists('/public_html/vendor/router/message.php') /public_html/vendor/core/Controler.php:33
                                               >=> FALSE
    0.0304     438336                         -> EControlerNotFound->__construct($object = class Router { public $dir = '/public_html/vendor/router/'; public $name = 'message'; public $file = '/public_html/vendor/router/message.php' }, $name = 'message', $file = '/public_html/vendor/router/message.php') /public_html/vendor/core/Controler.php:35
    0.0308      19352
TRACE END   [2017-01-17 00:19:00]