Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:11:10+00:00 2026-06-10T22:11:10+00:00

RT function 1 : $class->$func() function 2: //Simple callback call_user_func($func) //Static class method call

  • 0

RT

function 1 :

$class->$func()

function 2:

//Simple callback
call_user_func($func)
//Static class method call
call_user_func(array($class,$func))
//Object method call
$class = new MyClass();
call_user_func(array($class, $func));

Is there a difference? I want to see the sourcecode(https://github.com/php/php-src) should we do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:11:12+00:00Added an answer on June 10, 2026 at 10:11 pm

    call_user_func_array is very slow performance-wise, that’s why in many cases you want to go with explicit method call. But, sometimes you want to pass arbitrary number of arguments passed as an array, e.g.

    public function __call($name, $args) {
        $nargs = sizeof($args);
        if ($nargs == 0) {
            $this->$name();
        }
        elseif ($nargs == 1) { 
            $this->$name($args[0]);
        }
        elseif ($nargs == 2) { 
            $this->$name($args[0], $args[1]);
        }
        #...
        // you obviously can't go through $nargs = 0..10000000, 
        // so at some point as a last resort you use call_user_func_array
        else { 
            call_user_func_array(array($this,$name), $args);
        }
    }
    

    I’d go with checking $nargs up to 5 (it’s usually unlikely that a function in PHP accepts more than 5 arguments, so in most cases we will call a method directly without using call_user_func_array which is good for performance)

    The result of $class->method($arg) is the same as call_user_func_array(array($class,'method'), array($arg)), but the first one is faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any Java function or util class which does rounding this way: func(3/2)
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? Why following code
I am writing a simple piece of code. class A { public: virtual func
I have a base class which has a nested type, inside. There's a function
Simple question, but tough answer? I have the following anonymous function inside a class
I wanted to export a simple function from a base class that I use
I have a simple function that uses a callback and I want use functor
How can I tell if a class instance method and function are the same?
I have a Exception base class which defines a stream function: class Exception {
Say I have a type with a member function: class Thing { std::string m_name;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.