<?php//Magic Method//When containing multiple classes of//1. Magic method for automatically loading classes __autoload () function __autoload ($classname) {if (Isset ($classname)) {require_ Once $classname. '
Class.php ';
}/* $computer 1=new Computer ();
$computer 1->addlist (' Dalisng ', 234); echo $computer 1;
* *//__call () mask the error generated when invoking the method, the __call () method is automatically invoked when we call a nonexistent method.
Independent examples, two examples were established respectively, Non-interference $computer 2=new Computer ();
echo $computer 2->name;echo "<br/>";
$computer 3=new Computer ();
echo $computer 3->name;echo "<br/>";
$computer 3->name= "Big bright";
Echo ' $computer 3->name: '. $computer 3->name;echo "<br/>";
Echo ' $computer 2->name: '. $computer 2->name;echo "<br/>";
echo "
Computer.class.php
<?php
class computer{public
$name = "1234";
function __construct () {
echo "you are right!";
}
function __call ($methodName, $argsList) {//This method is called automatically when the method does not exist, $argsList is the corresponding parameter
echo $methodName. " () method does not exist! ";
echo "<pre>";
Print_r ($argsList);
echo "</pre>";
}
Private Function __tostring () {///when the user outputs a string that does not exist, the method automatically invokes the Echo object name
echo "I am the object's string!" ";
}
}
The above is a small series for everyone to bring the PHP magic method as well as on independent examples and connected to a full explanation of the case of all the content, I hope that we support cloud Habitat Community ~