簡體   English   中英

__callStatic沒有調用我的非靜態函數

[英]__callStatic is not calling my non-static function

我認為這會奏效,但事實並非如此。

class Foo {
    public function send($to, $message)
    {
        echo 'sending';
    }
    public static function __callStatic($method, $params)
    {
        return call_user_func_array(array(new static, $method), $params);
    }
}

當我做Foo::send('mary','you had a little lamb') ,為什么它仍然調用Foo::send()而不是new Foo ->send($to, $message)

Non-static method Foo::send() should not be called statically, assuming $this from incompatible context

根據手冊

在靜態上下文中調用不可訪問的方法時會觸發__callStatic()。

您的方法不可訪問,它存在且可訪問,它不是靜態的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM