How to alias a function in PHP?

前端 未结 15 1240
死守一世寂寞
死守一世寂寞 2020-11-30 00:13

Is it possible to alias a function with a different name in PHP? Suppose we have a function with the name sleep. Is there a way to make an alias called wa

15条回答
  •  忘掉有多难
    2020-11-30 01:11

    What I have used in my CLASS

    function __call($name, $args) {
        $alias['execute']=array('done','finish');
        $alias['query']=array('prepare','do');
        if (in_array($name,$alias['execute'])){
            call_user_func_array("execute",$args);
            return TRUE;
        }elseif(in_array($name,$alias['query'])){
            call_user_func_array("query",$args);
            return TRUE;
        }
        die($this->_errors.' Invalid method:'.$name.PHP_EOL);
    }
    

提交回复
热议问题