PHP inside Call_user_func and $class-> $func () the Difference

Source: Internet
Author: User
Rt

One is

$class-$func ()

The other one is

Simple Callbackcall_user_func ($func)//static class method Callcall_user_func (Array ($class, $func))//object method Call$class = new MyClass (); Call_user_func (Array ($class, $func));

What is the difference between the two? What if I want to see what the source implementation should do? Answer this question to find a way!

Reply content:

Rt

One is

$class-$func ()

The other one is

Simple Callbackcall_user_func ($func)//static class method Callcall_user_func (Array ($class, $func))//object method Call$class = new MyClass (); Call_user_func (Array ($class, $func));

What is the difference between the two? What if I want to see what the source implementation should do? Answer this question to find a way!

I recommend that you first install an extension that looks at opcode and compare the generated opcode. This should be the quickest to understand the different scenarios between the code. Many of the different things you want to know can be used in this way, such as how print and echo are different, and so on.

Off-topic, just as many C + + programmers optimize code often observe the compiler generated assembly code, whether some of the writing style of PHP will have an impact on performance or by looking at opcode to get answers.

It doesn't make much difference, it is to find the corresponding function from the symbol table head and call it.

can refer to PHP source code PHP-5.XXXXX/ZEND/ZEND_EXECUTE_API.C in the implementation of call_user_function this function.

Not much to say what
$class-$func (), if $func does not exist, is reported fatal Error
The Call_user_func (Array ("Class", "Func")) is reported warning
You'll know how to choose the application scenario in your project.

Call_user_func () is not used in many cases, Call_user_func_array () Use more cases, usually used for function parameters of the function of the call

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.