Php magic method call details

Source: Internet
Author: User
Tags magic call
Php magic call explanation author: zccstclassCaller {private $ xarray (, 3); publicfunction _ call ($ m, $ a) {printMethod $ mcalled: n; var_dump ($ a); retur php magic method call details
Author: zccst

Class Caller {private $ x = array (1, 2, 3); public function _ call ($ m, $ a) {print "Method $ m called: n "; var_dump ($ a); return $ this-> x ;}}$ foo = new Caller (); $ a = $ foo-> test (1, "2", 3.4, true); var_dump ($ );


Output result:
Method test called: n

Array
0 => int 1
1 => string '2' (length = 1)
2 => float 3.4
3 => boolean true

Array
0 => int 1
1 => int 2
2 => int 3


Annotation:
_ Call () is a magic method in PHP. when you call a method in a class that does not exist, it will automatically call _ call ();

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.