Talked about the problem of using require_once to still tell that the class was redefined. So I think of the phenomenon I encountered the other day. Here and everyone to say, today only think of the specific reasons, if you do not say it is almost forgotten. It seems that everything is not through the brain, the brain's level two cache, and memory, and even hard disk are small poor. Well.
Assuming the following three files, the c.php a.php b.php corresponding storage directory is: Localhost/localhost/localhost/demo
The code is as follows |
Copy Code |
c.php Require_once ("a.php"); Require_once ("demo/b.php"); B::d emo (); a.php Class A { } |
B.php's content is interesting, because it has to inherit CLASS A, so I put a.php into it.
|
copy code |
require_once ("... /a.php "); Class B extends A { public static function demo () { echo "xx"; } } |
Execute localhost/c.php system error, error message as follows
Warning:require_once (.. /a.php) [Function.require-once]: failed to open stream:no such file or directory in f:wwwdemob.php on line 2
Fatal err Or:require_once () [function.require]: Failed opening required '. /a.php ' (include_path= '); C:php5pear ') in f:wwwdemob.php on line 2 However, surprised to find that if the b.php inside the require_once statement, the execution of normal, then must be require_once statement definition more? The reason is that class A has been redefined two times? But it won't. If I only add require_once (' a.php ') to the c.php, this statement, even if I write two times is true, what is the matter?
The reason is that the directory hierarchy of the b.php definition and the c.php execution file is inconsistent, resulting in two require_once statements inside the c.php. Make it equal to
The code is as follows |
Copy Code |
Require_once ("a.php"); Require_once (".. /a.php "); Class B extends A { public static function demo () { echo "XX"; } } B::d emo (); |
The reason was found, because inside the c.php, its relative directory "..." Is the c.php of the previous layer, resulting in files can not find an error.
Therefore, we conclude that in PHP, when using require_once, there are different levels of relationships, and there is relative to the use of the directory must be cautious, careful.
http://www.bkjia.com/PHPjc/632201.html www.bkjia.com true http://www.bkjia.com/PHPjc/632201.html techarticle talked about the problem of using require_once to still tell that the class was redefined. So I think of the phenomenon I encountered the other day. Here and everyone to say, today only think of the specific reasons, ...