Today, however, I found that the _ autoload magic method is too specific or you are willing to call it a magic function. When he loads the class files to be included, he does not even need to declare anything other than the class defined in the class files.
Start to play back this mechanism.
First, create a Test. class. Php file and type the following content:
| The code is as follows: |
Copy code |
|
$ PublicPara = 'When did the 17th CPC National Congress be held? ';
Class Test {
Public function _ construct (){
Global $ publicPara;
If (isset ($ publicPara )){
Echo $ publicPara;
}
Else {
Echo "what's my problem? ";
}
}
}
Note |
You have to save this file!
Create a new file named do. php and type the following content:
| The code is as follows: |
Copy code |
<? Php
Require_once ('test. class. Php ');
New Test ();
?> |
In this case, the output is as expected: When did the 17th CPC National Congress be held?
But when you use the _ autoload magic method, the problem arises.
| The code is as follows: |
Copy code |
|
<? Php
Function _ autoload ($ classname ){
Require_once ($ classname. ". class. php ");
}
New Test ();
?> |