dongwo5686 2011-06-09 01:39
浏览 87
已采纳

在包含包含它的文件后,PHP不会实例化该类

Here is my problem. I have one file (say, func.inc.php) with autoloader function, registered by spl_autoload_register():

function autoloaderFnc($class) {
    global $__CONFIG;

    $original = $class_name;
    $class_name = mb_strtolower ( $class_name );

    foreach ( $__CONFIG ['include_dirs'] as $path ) {
        if(file_exists ( $__CONFIG ['root'] . $path . $class_name . '.inc.php' )) {
            require ($__CONFIG ['root'] . $path . $class_name . '.inc.php');

            $classFound = TRUE;
            $foundAt = $__CONFIG ['root'] . $path . $class_name . '.inc.php';
            break;
        }
    }

    if( $classFound ) {
        if ( class_exists( $original ) ) {
            return true;
        } else {
            $backtrace = debug_backtrace();
            $error = "PHP User error: Cannot load class <b>$original</b> included at " . $backtrace[1]['file'] . ":" . $backtrace[1]['line'] . " (searching for <i>$class_name.inc.php</i>), but following file was included: $foundAt";
            error_log( $error );

            return false;
        }
    } else {
        $backtrace = debug_backtrace();
        $error = "PHP User error: Cannot find file with class <b>$original</b> included at " . $backtrace[1]['file'] . ":" . $backtrace[1]['line'] . " (searching for <i>$class_name.model.php</i> and <i>$class_name.inc.php</i>) in none of the following include dirs:<br />" . join ( '<br />', $__CONFIG ['include_dirs'] );
        error_log( $error );
    }

}

spl_autoload_register('autoloaderFnc');

Then I have a second file (show_me_poi.php), calling some class:

POI::doSmth();

Everything seems OK, but sometimes (and only sometimes!) I receive a following error in log:

[error] PHP User error: Cannot load class POI included at /path_to_dir/php/generators/export.generator.php:156 (searching for poi.inc.php), but following file was included: /path_to_dir/php/scripts/php/incs/poi.inc.php

This is weird, because class POI is defined in properly included file! And I repeat, this situation happens only sometime (10 out of 100 I think). What can cause such behaviour? And how can I fix it?

Thanks in advance!

展开全部

  • 写回答

2条回答 默认 最新

  • doujiao2000 2011-07-06 06:20
    关注

    The problem seems to arise only with APC op-cache turned on. I think that __autoload function can't work properly with caches in some cases. AFAIS only some PHP and APC versions are not compatible with each other.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部