Solve the problem with the following code

Source: Internet
Author: User
What's the problem with the following code? a piece of code about php's automatic file loading
Public static function userAutoload ($ class_name) {// process the identified (core class in the framework) // class name and class file ing array $ framework_class_list = array (// 'class name' => 'class file address ''controller' => FRAMEWORK_PATH. 'controller. class. php', 'model' => FRAMEWORK_PATH. 'model. class. php ', 'Factory' => FRAMEWORK_PATH. 'factory. class. php', 'mysqldb' => FRAMEWORK_PATH. 'mysqldb. class. php', 'sessiondb' => TOOL_PATH. 'sessiondb. class. php ',); // determine whether it is a core class if (isset ($ framework_class_list [$ class_name]) {// It is a core class require $ framework_class_list [$ class_name];} // determine whether it can be added (controller class, model class) // controller class, which is followed by a character and matches Controllerelseif (substr ($ class_name,-10) = 'controller') {// Controller class, the current platform's controller directory require CURRENT_CONTROLLER_PATH. $ class_name. '. class. php ';} // Model class, which contains the last five characters and matches Modelelseif (substr ($ class_name,-5) = 'model') {// Model class, the model directory in the current platform is require CURRENT_MODEL_PATH. $ class_name. '. class. php ';}}/*** register to automatically load */private static function _ initAutoload () {spl_autoload_register (array (_ CLASS __, 'userautoload');}]


Reply to discussion (solution)

Where do you call the _ initAutoload method?

Where do you call the _ initAutoload method?


In another method of the current class, it is called through static: _ initautoload.

Fixed the case sensitivity issue for automatic loading.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.