简体   繁体   English

我的自动加载代码有什么问题

[英]What's wrong in my autoload code

I did test both of codes to autoload Classes to page,But not work for me!我确实测试了两个代码以将类自动加载到页面,但对我不起作用!

What's wrong ?怎么了 ?

spl_autoload_extensions('.php, .class.php');
    spl_autoload_register(function ($name){
        if('inc/'."{$name}".'.class.php'){
            require('inc/'."{$name}".'.class.php');
        }
    });

AND :和 :

class FW{
        public static function autoload($class){
            $class = strtolower($class);
            $fpath = realpath(dirname(__FILE__)).'/inc/'."{$class}". '.class.php';
            if(is_readable($fpath)){
                require_once($fpath);
            }
        }
    }

    spl_autoload_register('FW::autoload');

As my question have not answer I reply answer and hope it will be useful.由于我的问题没有回答,我回复了答案,希望它会有用。 I add the code to Config.php and edit classes name style form whatever.class.php to class.whatever.php and it's work for me.我将代码添加到 Config.php 并将类名称样式从whatever.class.php编辑为class.whatever.php ,它对我class.whatever.php

    //  Classes Autoloader
    spl_autoload_extensions('.php, .class.php');
    spl_autoload_register(function ($name){
        if(is_readable(realpath(dirname(__FILE__)).'/inc/class.'."{$name}".'.php')){
            require(realpath(dirname(__FILE__)).'/inc/class.'."{$name}".'.php');
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM