php类magick函数__call不起作用

时间:2015-03-05 10:28:59

标签: php class call

您好我通过使用magick类函数__call尝试存储调试信息,但没有任何存储在....

__呼叫

function __call($method, $arguments)
{

    $load_functions = array('get', 'insert', 'update', 'delete', 'rawQuery');

    if(in_array($method, $load_functions))
    {

        array_push($this->_debug, microtime(true));

    }

}

执行

$app->database->setbase('MyBase');
$query = $app->database->get('MEMB_INFO');

$app->database->debug();

没有任何内容存入$ this-> _debug数组... $ app-> database-> debug();返回空数组。

1 个答案:

答案 0 :(得分:3)

仅对非现有方法调用Magic方法__call。但我想你的方法存在。

如果你真的想检查调用的方法,你可以使用装饰器。它是包含原始类实例的类,与原始类具有相同的接口,并且每个方法调用被委托回原始对象。您可以向装饰器方法添加自定义调试逻辑(或使用__call并创建通用调试装饰器)。当然你需要将装饰器实例注入$ app->数据库。它可以通过多种方式完成,取决于您的框架和环境(prod vs. dev等)。

我在想什么 - Logging all Soap request and responses in PHP