Do not understand the call_user_func_array and the referenced code.

Source: Internet
Author: User
Do not understand the call_user_func_array and the referenced code.
class PbObject{var $params;var $fontFace = 'incite.ttf';function Object() {$args = func_get_args();if (method_exists($this, '__destruct')) {register_shutdown_function (array(&$this, '__destruct'));}call_user_func_array(array(&$this, '__construct'), $args);}function __construct(){}function toString() {$class = get_class($this);return $class;}}



In this code, will call_user_func_array (array (& $ this, '_ construct'), $ args); why is a quote prefixed with $ this &? I have never understood such code. Can the _ construct method be called without adding or not? What is the role of adding?


Reply to discussion (solution)

When call_user_func_array calls a class method, the class (object) and method name must be transmitted simultaneously with arrays.
Your $ this is the object.
In php4, the object is passed as a value by default. If no declaration (&) is referenced, it is actually executed on another object. if the class attribute is modified in the method, the modification will not apply to the caller.
In php5, all objects are passed by reference, so there is no need to name &

In your code, use var to declare class attributes, which is obviously php4-style
Php4 class has no destructor, so the code uses register_shutdown_function to register



I used to learn about the version.

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.