The following small series will provide you with a PHP magic method and a comprehensive explanation of independent instances and connected instances. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
<? Php // magic method // When containing multiple classes // 1. magic _ autoload () function _ autoload ($ classname) {if (isset ($ classname) {require_once $ classname. '. class. php ';}}/* $ computer1 = new Computer (); $ computer1-> addList ('dalisng', 234); echo $ computer1; * ///_ call () block errors generated when calling a method. when we call a method that does not exist, the _ call () method is automatically called. // Independent instance. The two instances are created separately and do not interfere with each other $ computer2 = new Computer (); echo $ computer2-> name; echo"
"; $ Computer3 = new Computer (); echo $ computer3-> name; echo"
"; $ Computer3-> name =" "; echo '$ computer3-> name:'. $ computer3-> name; echo"
"; Echo '$ computer2-> name:'. $ computer2-> name; echo"
"; Echo"
"; // Connect to an instance, that is, use an equal sign to open up a new instance. at this time, the two instances point to a memory address, with a loss of both, and the loss of both instances $ computer4 = new Computer (); echo '$ computer4-> name :'. $ computer4-> name; echo"
"; $ Computer5 = $ computer4; echo '$ computer5-> name:'. $ computer5-> name; echo"
"; $ Computer4-> name =" "; echo '$ computer4-> name:'. $ computer4-> name; echo"
"; Echo '$ computer5-> name:'. $ computer5-> name; echo"
"; Echo"
"; // Clone _ clone: The new instance to be cloned and the instance to be cloned are two independent individuals. Although the attribute values are the same, the address where the attributes are stored is different, so after cloning, you have nothing to do with life and death. $ computer6 = new Computer (); echo '$ computer6-> name :'. $ computer6-> name; echo"
"; $ Computer7 = clone $ computer6; echo '$ computer7-> name:'. $ computer7-> name; echo"
"; $ Computer6-> name =" clone "; echo '$ computer6-> name:'. $ computer6-> name; echo"
"; Echo '$ computer7-> name:'. $ computer7-> name; echo"
";
Computer. class. php
<? Phpclass Computer {public $ name = "1234"; function _ construct () {echo "you are right! ";} Function _ call ($ methodName, $ argsList) {// This method is automatically called when the method does not exist. $ argsList is the corresponding parameter echo $ methodName. "() method does not exist! "; Echo"";print_r($argsList);echo "
";} Private function _ toString () {// when the user outputs a non-existent string, this method is automatically called, for example, echo object name echo" I am the object's string! ";}}
The above is the PHP magic method provided by Xiaobian and a comprehensive explanation of the independent instances and connected instances. I hope you can support the scripts ~