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:)