PHP:从未调用__autoload函数 [英] PHP: __autoload function doesn't ever called
问题描述
所以,我有xampp.我在ZendServer上测试了此代码,结果相同.
So, I have xampp. I tested this code on ZendServer, result the same.
<?php
error_reporting(E_ALL);
define ("ABS_PATH", 'C:\xampp\htdocs\oopHotLine\\');
function __autoload($class_name) {
echo 'gg';
require_once (ABS_PATH.'classes\\'.$class_name.'.php');
}
$process=new Main('1');
?>
在php.exe -a index.php之后,我有这个:
after php.exe -a index.php i have this:
Interactive mode enabled
Fatal error: Class 'Main' not found in C:\xampp\htdocs\oopHotLine\index.php on line 10
[Finished]
因此,它不会显示"gg"输出.如果我手动执行__autoload('Main'); - 一切都好.手册require_once或include的内容相同. Windows文件夹中的所有权限都设置为完全访问权限. PHP版本-PHP版本=> 5.3.8;
so, it doesn shows 'gg' output. If i manually do __autoload('Main'); - all OK. The same for the manual require_once or include. All permissions in windows folder set to full access. Php version - PHP Version => 5.3.8;
请帮助.
推荐答案
正如DaveRandom指出的那样:
As DaveRandom pointed:
Autoloading is not available if using PHP in CLI interactive mode.
因此,不要使用php.exe -a index.php
,而是要切断-a
并尝试使用 php.exe index.php
运行脚本.
So, instead of using php.exe -a index.php
, cut the -a
off and try running the script with php.exe index.php
instead.
这篇关于PHP:从未调用__autoload函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!