[PHP] laravel 中__callStatic的使用

当使用laravel的日志类记录信息的时候

Log::info("xxxx")

发现Log类里并没有定义info 静态方法,但是仍然可以调通

原因就是__callStatic魔术方法,当静态方法不存在的时候,会调用这个魔术方法

 

 

简单的测试用例

<?php

/**
 * Class Log
 * @method static void info()
 * @see Test
 */
class Log{
    public static function __callStatic($method, $args){
        $test=new Test();
        $test->$method($args);
    }
}

class Test{
    public  function info($args){
        var_dump($args);
    }
}


Log::info("hello","world");

 

posted @ 2021-07-28 17:07  唯一客服系统开发笔记  阅读(116)  评论(0编辑  收藏  举报