18
2019
09

PHP对象不存在call()、callStatic()

call()

  在对象中调用一个不可访问方法时,__call()会被调用

callStatic()

  在静态上下文中调用一个不可访问方法时,__callStatic()会被调用

<?php
class MethodTest 
{
    public function __call($name, $arguments) 
    {
        echo "Calling object method '$name' "
             . implode(', ', $arguments). "\n";
    }
    public static function __callStatic($name, $arguments) 
    {
        echo "Calling static method '$name' "
             . implode(', ', $arguments). "\n";
    }
}
$obj = new MethodTest;
//Calling object method 'runTest' in object context
$obj->runTest('in object context');
//Calling static method 'runTest' in static context
MethodTest::runTest('in static context');  
?>

原文链接:https://www.qiquanji.com/post/7987.html

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注

更新实时通知

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。