PHP Common Magic Method (__call Magic Method:)

Source: Internet
Author: User
Tags autoload

Magic Method __call

<?PHP//file name: index.phpDefine(' A ',__dir__);include'/imooc/loader.php '; Spl_autoload_register (' \\imooc\\loader::autoload ');$Object=New\imooc\Object();Echo $Object->test ("Ouch-hello", 123);//the __call method is called automatically when you call a method that does not exist with test/*Output: String (4) "Test" Array (2) {[0]=>string (9) "Ouch-fed" [1]=>int (123)} try*/
<? PHP
file name: object.php

namespace Imooc; class Object { function __call ($name$arguments)//$name method name =test,$ Arguments parameter = "Ouch-hello", 123 { var_dump($name,$arguments ); return "Give it a Try"; }}

Static Magic Method __callstatic

<?php
//Filename:index.php
Define(A,__dir__);
Include'/imooc/loader.php ';
Spl_autoload_register (‘\\Imooc\\Loader::autoload ');


$Object=New\imooc\object ();
EchoImooc\object::Test ( "Hello1" , 1234 );
/*
String (4) "Test"
Array (2) {
[0]=>string (6) "Hello1"
[1]=>int (1234)
}

*/
<?phpnamespace Imooc;//file name: object.phpclass Object{    //Static Methods    Static function__callstatic ($name,$arguments)//$name static method name =test, $arguments parameter array = "Ouch-hello", 123    {        Var_dump($name,$arguments); return"Give it a try."; }}

PHP Common Magic Method (__call Magic Method:)

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.