Onion
Onion

Reputation: 1832

Passing zero parameters to call_user_func_array

Consider the following situation:

call_user_func_array(array($this, 'method'), array());

This works fine, but I'm wondering whether this is the right way to pass zero parameters to the method. I've tried passing null instead of array(), but that gives me an error.

Question: what is the right way to pass zero arguments to the method called by call_user_func_array?

Upvotes: 0

Views: 82

Answers (1)

message
message

Reputation: 4603

Yes, you can use call_user_func. See an example

<?php
class MyClass
{

    public function callableFunc()
    {
        echo "Called" . PHP_EOL;
    }

    public function call()
    {
        echo "Calling callable from other function" . PHP_EOL;
        call_user_func(array($this, 'callableFunc'));
    }

}

$class = new MyClass;

call_user_func(array($class, 'callableFunc'));
$class->call();

Upvotes: 1

Related Questions