我正在使用spl_autoload_register以加载类。
我有一个index.php包含文件的init.php文件。该spl_autoload_register函数在init.php文件中调用。
在index.php文件中,它可以正常工作:我可以创建类和东西,它们的名称已解析。
但后来,在 中index.php,我包含了另一个文件,work.php以执行某些特定任务。
奇怪的是,在 中work.php,找不到我正在使用的类。
如果我spl_autoload_register再次调用 in work.php,则可以解决该类。
真正奇怪的是这种行为并不一致:在我的测试服务器上,我不必重复spl_autoload_register调用,但在我的生产服务器上,这是强制性的。
我错过了一些选项php.ini吗?
编辑/更新:这是init.php文件上的内容,以防万一:
<?php
function my_autoload($class){
include 'class/' . $class . '.class.php';
}
spl_autoload_register('my_autoload');
?>
我的 index.php :
<?php
require_once 'include/init.php';
$barcode = new Barcode();
// here is a bunch of test and stuff
include 'work.php';
?>
我的 work.php :
<?php
$myObj = new Barcode();
// more useles stuff
?>
条形码在 index.php 代码部分完美创建,但在 work.php 部分失败......