Home >Backend Development >PHP Tutorial >Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

WBOY
WBOYOriginal
2016-12-01 00:26:041117browse

Running environment description:
Referring to foo.php (file2) in the index.php (file1) file
Problem:
As long as the namespace (namespace testindex) is declared in index.php, an error will be reported.

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Reply content:

Running environment description:
Referring to foo.php (file2) in the index.php (file1) file
Problem:
As long as the namespace (namespace testindex) is declared in index.php, an error will be reported.

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Because you added the namespace, the function __autoload() is also applied to this namespace, that is, calling this function becomes testindex__autoload(), then PHP cannot find the function __autoload() and cannot Complete the automatic loading process.

One is the result of the commented out namespace, and the other is not.
Why does this happen?
//-------------------------------------------------- -------------
Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Regarding the issue of automatic loading of namespaces

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn