1. 程式人生 > >call_user_func 具體使用方法,實例說明

call_user_func 具體使用方法,實例說明

format 直接 fun spa nbsp 靜態方法 span pre call

<?php

class Person{
    public $name="jack";
    
    public static function say(){
        echo "ok";
    }
    public static function say2($words){
        echo $words;
    }
    
    public function name(){
        echo $this->name;
    }
    public function call($num){
        
echo $this->name." call ".$num; } } function get_date($format){ echo date($format); } $jack=new Person; //1.調用對象 方法 call_user_func([$jack,"name"]); //2.調用對象 方法帶參數 call_user_func([$jack,"call"],‘119‘); //3.調用類的靜態方法 call_user_func([‘Person‘,"say"]); //4.調用類的靜態方法帶參數 call_user_func
([‘Person‘,"say2"],‘hello world‘); //5.直接調用全局方法(當然也可以不帶參數) call_user_func("get_date",‘Y-m-d‘); //6.調用匿名函數(當然也可以不帶參數) call_user_func(function($event){ echo "anonymous function".$event; },‘1‘);

call_user_func 具體使用方法,實例說明