A solution to the conflict between __autoload and Smarty3 in PHP

Source: Internet
Author: User
Tags autoloader learn php

Today, Smarty to 3.0 was updated and found that the __autoload () in the project was not available,

As a novice beginner to learn PHP, engaged in a half-day to understand the problem in their conflict, depressed for several days. After viewing, Smarty3.0 in the Smarty2_bc_notes file, learned that Smarty3.0 and PHP __autoload () Conflict:

——————————————————————————-——-

= = Autoloader = =

Smarty 3 does register its own autoloader with Spl_autoload_register. If Your code has

An existing __autoload function then this function must is explicitly on

The __autoload stack. http://us3.php.net/manual/en/function.spl-autoload-register.php

For further details.

——————————— —————————————————————

The workaround is to register your own add-in class with Spl_autoload_register ().

Now give the code before and after the configuration:

————————————————————————————————————

  if (substr ($className,-6) = = "Action") {include (App_class_path. ' action/'. $className. ")   
  Class.php "); }elseif (substr ($className,-5) = = "Model") {include (App_class_path. ' model/'. $className. ").   
  Class.php "); }elseif ($className = = "Smarty") {require_once net_root. "   
  Smarty/smarty.class.php "; }elseif (substr ($className,-6) = = "Public") {include (App_class_path. ' public/'. $className. ")   
  Class.php "); —————————————————————————————— class Classautoloader {public Function __construct () {Spl_autoload_reg   
 Ister (Array ($this, ' loader '));   
   The Private Function loader ($className) {if (substr ($className,-6) = = "Action") {echo ' 1 '; Include App_class_path. ' action/'. $className. ".   
  Class.php ");   
   }elseif (substr ($className,-5) = = "Model") {echo ' 2 '; Include App_class_path. ' model/'. $className. ".   
  Class.php ");   
   }elseif ($className = = "Smarty") {echo ' 3 '; Require_once net_root. "   
  Smarty/smarty.class.php "; }elseif (SubsTR ($className,-6) = = "Public") {echo ' 4 '; Include App_class_path. ' public/'. $className. ".   
  Class.php "); }} $autoloader = new Classautoloader ();

Hope to help meet the problem of friends, so that everyone less detours.

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.