It seems that this function did not exist before php5. Now let’s take a look at the use of the new autoload magic method. When you understand it, you think it is so magical. Okay, without further ado, let’s take a look at the test filtering.
However, today I found that this __autoload magic method or you want to call it a magic function is too specific. When he loads the class file that needs to be included, it does not even care about other statements in the class file other than the class definition.
Start replaying this mechanic.
First we create a Test.class.php file and type the following content
The code is as follows
代码如下 |
复制代码 |
$publicPara='中共十七大啥时候召开的?';
class Test{
public function __construct(){
global $publicPara;
if(isset($publicPara)){
echo $publicPara;
}
else{
echo "管我啥事儿了?";
}
}
}
记
|
|
Copy code
|
$publicPara='When will the 17th National Congress of the Communist Party of China be held? ';
class Test{
public function __construct(){
global $publicPara;
if(isset($publicPara)){
echo $publicPara;
}
else{
echo "What do you care about me?";
}
}
}
代码如下 |
复制代码 |
require_once('Test.class.php');
new Test();
?> |
Remember
代码如下 |
复制代码 |
function __autoload($classname){
require_once($classname.".class.php");
}
new Test();
?>
|
You have to save this file! |
Then create a new file named do.php and type the following content
In this case, the output is just as we expected: When will the 17th National Congress of the Communist Party of China be held?
But when you use the magic method __autoload, problems arise
The code is as follows
|
Copy code
function __autoload($classname){
require_once($classname.".class.php");
}
new Test();
?>
http://www.bkjia.com/PHPjc/631679.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631679.htmlTechArticleIt seems that this function did not exist before php5. Now let’s take a look at how to use the new autoload magic method. After you get to know him, you think he is amazing. Okay, without further ado, take a look...
|
|