This article mainly introduces the implementation of the Magic method of PHP and about the independent instance and connected instances, interested in the friend's reference, I hope to help you.
Specific as follows:
<?php//Magic Method//When containing multiple classes//1. Magic method for automatic loading of 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, and when we call a nonexistent method, the __call () method is called automatically. Independent instances, each of the two instances were established, each non-interference $computer2=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
<?phpclass computer{public $name = "1234"; function __construct () {echo "You is 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>";p Rint_r ($argsList); echo "</pre>";} Private Function __tostring () {///when the user outputs a string that does not exist, the method automatically calls the Echo object name echo "I am the object's string!" ";}}
Summary: The above is the entire content of this article, I hope to be able to help you learn.