Accept function as parameter in PHP

后端 未结 8 772
Happy的楠姐
Happy的楠姐 2020-11-28 06:22

I\'ve been wondering whether is possible or not to pass a function as parameter in PHP; I want something like when you\'re programming in JS:

object.exampleM         


        
8条回答
  •  野性不改
    2020-11-28 07:01

    It's possible if you are using PHP 5.3.0 or higher.

    See Anonymous Functions in the manual.

    In your case, you would define exampleMethod like this:

    function exampleMethod($anonFunc) {
        //execute anonymous function
        $anonFunc();
    }
    

提交回复
热议问题