0

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?

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

What about object structures? I need to call a method of this.
@doitmyway you mean like this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.