Passing static methods as arguments in PHP

前端 未结 7 1514
温柔的废话
温柔的废话 2021-02-02 07:34

In PHP is it possible to do something like this:

myFunction( MyClass::staticMethod );

so that \'myFunction\' will have a reference to the stati

7条回答
  •  甜味超标
    2021-02-02 08:26

    As of PHP 7.4, this is convenient and IDE-friendly:

    myFunction(fn() => MyClass::staticMethod());
    

提交回复
热议问题