1. The first time we call the methods in different pages of the class
Test.phprequire_once ' test1.php '; require_once ' test2.php '; Test1\ceshi (); Call way namespace \ Function name Test2\ceshi ();//Call way namespace \ Function name
namespace test1;function Ceshi () { // file full path and filename such as D:\sfc\ceshi\mooc\test1.php}
Namespace Test2;function Ceshi () {echo __file__;//file full path and filename such as D:\sfc\ceshi\mooc\test2.php}
2. Imagine that each file is manually introduced is too cumbersome, if you can use that to introduce the good, some, there is a function __autoload () {} can be implemented
//the solution is to customize the auto-load function and use Spl_autoload_register to register the auto-load functionSpl_autoload_register (' Autoload2 '); Test\test1:: Ceshi ();//call static method format--namespace name \ class Name:: Static method NameTest\test2::Ceshi ();functionAutoload2 ($class){//Define the Introduction file function//echo $class ===> test\test1 List($namespace,$fileName) =Explode(‘\\‘,$class); require__dir__. ' \\‘.$fileName.‘. Php;}
<? phpnamespace Test; class test1{ publicstaticfunction Ceshi () { Echo __method__; Returns the name of the class and the name of the method
Echo ' </br> ';}}
1 namespace Test; 2 class test2{3 Public Static function Ceshi () {4 Echo __method__ // Returns the name of the class and the name of the method 5 Echo ' </br> '; 6 }7 }
PHP Auto-load Evolution