How to use call_user_func_array() to call a callback (method in class in namespace) with an array of parameters in PHP

2 Answers

0 votes
namespace ns;

class cl {
    static public function func($arg, $arg2) {
        echo "method: " . __METHOD__, " arg1: $arg arg2: $arg2";
    }
}

call_user_func_array(__NAMESPACE__ .'\cl::func', array("a", "b"));

 
/*
run: 

method: ns\cl::func arg1: a arg2: b 

*/

 



answered Jun 3, 2016 by avibootz
0 votes
namespace ns;

class cl {
    static public function func($arg, $arg2) {
        echo "method: " . __METHOD__, " arg1: $arg arg2: $arg2";
    }
}

call_user_func_array(array(__NAMESPACE__ .'\cl', 'func'), array("a", "b"));

 
/*
run: 

method: ns\cl::func arg1: a arg2: b 

*/

 



answered Jun 3, 2016 by avibootz
...