Reference to static method in PHP?

前端 未结 8 2398
伪装坚强ぢ
伪装坚强ぢ 2021-02-18 18:20

In PHP, I am able to use a normal function as a variable without problem, but I haven\'t figured out how to use a static method. Am I just missing the right syntax, or is this

8条回答
  •  失恋的感觉
    2021-02-18 19:11

    PHP handles callbacks as strings, not function pointers. The reason your first test works is because the PHP interpreter assumes foo1 as a string. If you have E_NOTICE level error enabled, you should see proof of that.

    "Use of undefined constant foo1 - assumed 'foo1'"

    You can't call static methods this way, unfortunately. The scope (class) is relevant so you need to use call_user_func instead.

    UseReferences();
    

提交回复
热议问题