For PHP loading operations and other two magic methods, load magic
<? Php
Load class
// Include ("./Ren. class. php ");
// Include "./Ren. class. php ";
Include_once ("./Ren. class. php ");
Include_once ("./Ren. class. php ");
$ F = new Ren ();
$ F-> test ();
Require ("./Ren. class. php ");
Require_once ("./Ren. class. php ");
Require_once "./Ren. class. php ";
$ F = new Ren ();
$ F-> test ();
Automatic loading class
// 1. All class names and class names must be consistent
// 2. Put all class files under the same file
// 3. The naming rules of all class files are consistent
Function _ autoload ($ cname ){
Require_once ("./$ cname. class. php ");
}
$ T = new test ();
$ T-> ceshi (). '<br> ';
$ S = new Ren ();
$ S-> test ();
Two magic methods
Class Ren {
Public $ name;
Public function say (){
Echo "output object method ";
}
// Method of the output object
Public function _ tostring (){
Echo "Another output method"; // echo $ s->__ tostring ();
Return "Another output method"; // echo $ s;
}
// Method for object cloning
Public function _ clone (){
$ This-> name = "Riven"; // $ this indicates a duplicate (cloned object)
}
}
$ S = new Ren ();
// Echo $ s->__ tostring (); // output string
// $ S-> say ();
$ S-> name = "Small V ";
Var_dump ($ s );
$ S1 = clone $ s;
Var_dump ($ s1 );
?>