zoukankan      html  css  js  c++  java
  • 框架编程之路一

    一:自动加载为啥舍弃__autoload() 而选用 spl_register_autoload() ?

    I experienced it while upgrading the Smarty and my own autoload function.
    
    So, the better way is to avoid __autoload() and use spl_register_autoload() instead. If you have written this already, just rename your function to something like __autoload_my_classes, and in the next, call spl_autoload_register as:
    
    <?php
    function __autoload_my_classes($classname)
    {
      # ... your logic to include classes here
    }
    spl_autoload_register('__autoload_my_classes');
    ?>
    
    1:You can assign multiple functions to spl_autoload_register() by calling it repeatedly with different function names. Be sure to limit your every function to include a CLASS file.(确保每个自动加载函数只包含一个class文件)
     
    注意:
    1、如果使用 PHP 的 CLI 交互模式 时,Autoloading 不存在。
    2、在 __autoload 函数中抛出的异常不能被 catch 语句块捕获并导致致命错误。
     
     参考:
    php自动加载: http://www.2cto.com/kf/201212/180553.html
    PHP autoload与spl_autoload自动加载机制的深入理解: http://www.jb51.net/article/37906.htm
     
     

     

  • 相关阅读:
    第二周编程总结
    介绍自己
    编程总结3
    PTA编程总
    PTA编程总结1
    《秋季学期学习总结》
    《人生路上对我影响最大的三位老师》
    介绍自己
    7-1 打印沙漏
    记叙在人生路上对你影响最大的三位老师
  • 原文地址:https://www.cnblogs.com/Alight/p/3565833.html
Copyright © 2011-2022 走看看