Warning: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback

✔ Recommended Answer

Just for the fun of it another one ... (not tested though).

class myClass{    protected $callback = 'myCallback';    protected $body = false;    public function myFunction()    {        ...        curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'test'));        ...    }    public function test($handle, $line)    {        if ($this->body) {            call_user_func($this->callback, $line);        }        if ($line === "\r") {            $body = true;        }        return strlen($line);    }}function myCallback($data) {    print $data;}$myCls = new myClass();$myCls->myFunction();
Method #2

This warning message usually appears in PHP when the first argument passed to the call_user_func() function is not a valid callback.

A callback is a function or method that can be passed as an argument to another function or method, and can be called later in the code execution.

To resolve the warning message, you should ensure that the first argument passed to call_user_func() is a valid callback. This can be a function name (string), an array containing an object and a method name, or a closure.

Here is an example of a valid callback using a function name:

function my_callback_function() { echo "Hello World!"; } call_user_func('my_callback_function');

Here is an example using an array containing an object and a method name:

class MyClass { public function myMethod() { echo "Hello World!"; } } $obj = new MyClass(); call_user_func(array($obj, 'myMethod'));

And here is an example using a closure:

$myClosure = function() { echo "Hello World!"; }; call_user_func($myClosure);

Make sure that you are passing a valid callback to call_user_func(), and the warning message should disappear.


Most Popular

PhpStorm, return value is expected to be 'A', 'object' returned

Remove Unicode Zero Width Space PHP

Laravel file upload returns forbidden 403, file permission is 700 not 755