Ec (2); after php5, the _ autoload interceptor method is introduced to automatically include and reference class files. We usually write this: copy the Code as follows: function _ autoload ($ classname) {include_once $ classname .. class. php;} $ usernewuser (); when the php engine attempts to instantiate an operation of an unknown class, it calls script ec (2); script
After php5, the _ autoload interceptor method is introduced to automatically include and reference class files. We usually write this:
The Code is as follows:
Function _ autoload ($ classname ){
Include_once $ classname. '. class. php ';
}
$ User = new user ();
When the php engine tries to instantiate an operation of an unknown class, it will call the _ autoload () method, and there is a last chance to load the required class before the php error fails. Therefore, when the above code is executed, the php engine automatically executes the _ autoload Method for us to include the file user. class. php.
The exception thrown in the _ autoload function cannot be caught by the catch statement block and cause a fatal error.
If you use the cli interaction mode of php, the automatic loading mechanism will not be executed.
If you want to use pear-style naming rules, such as introducing the user/register. php file, you can do the following:
The Code is as follows:
// Load me
Function _ autoload ($ classname ){
$ File = str_replace ('_', directory_separator, $ classname );
Include_once $ file. 'php ';
}
$ Userregister = new user_register ();
Homepage 1 2 last