Review PHP Magic method call

Source: Internet
Author: User

<?phpdeclare (Strict_types=1);//Open strong Type mode class person{public function Say () {echo "Hello world";    echo "\ r \ n"; }} (new Person ())->say ();//Call the method that exists in the class (New person ())->eat (' food ');//Call a method that does not exist in the class


Methods that do not exist in the calling class PHP Fatal error:uncaught error:call to undefined method person::eat () in/home/zrj/www/zhangrenjie_test/test/ 36.php:26stack Trace: #0 {main} thrown in/home/zrj/www/zhangrenjie_test/test/36.php on line 26



Class person{Public function Say () {echo ' Hello world ';    echo "\ r \ n";    }//__call () is called when an inaccessible method is called in the object. Public Function __call ($functionName, $arguments) {echo "You called a method that does not exist in the class:". $functionName.        "\ r \ n"; echo "Accepts parameters as:".    Print_r ($arguments, true); }} (new Person ())->say ();(the New Person ())->eat (' food ', ' chicken ', ' Bull ');


Hello World

You have called a method that does not exist in the class: Eat

The parameters accepted are: Array

(

[0] = food

[1] = cocal

[2] = Bull

)


This article is from the "My PHP path" blog, so be sure to keep this source http://phpme.blog.51cto.com/663593/1982125

Review PHP Magic method 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.