Heim >Backend-Entwicklung >PHP-Tutorial > php5中_autoload()的步骤为什么不能使用呢

php5中_autoload()的步骤为什么不能使用呢

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 13:25:511075Durchsuche

php5中__autoload()的方法为什么不能使用呢
每次在页面中用include_once("...");这样如果引用的类太多,就容易忘记include某个类,所以我想用__autoload()方法,

可是我一写function __autoload(){}就报错(在__autoload()下面画一条绿色的线,说明不存在该方法)。

我用的IDE是jetBrains PhpStorm4.0.1(不知道这个有没有影响)

不懂,求解。。。。

------解决方案--------------------
你的代码是正确的,如果是编辑器对 __autoload 报错,则说明你的 php 不是 5.0 以上的,或者是编辑器的字典太老了
------解决方案--------------------
include_once($class.".php"); //当前路径这样写就可以了
------解决方案--------------------
噢看到了,对了 phpstorm

下面出现一条绿色的下划线,它不是提示你这个有问题,而是提示你这个单词有问题,鼠标移动上去后会出现两行选择操作,将这个单词添加入字典里就行了.

Typo:Save "xxxx" to dic....

算是phpstorm 的小bug吧
------解决方案--------------------
function __autoload($class){
include_once("path".$class.".php");
}
错了,改为include_once("path/".$class.".php");

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel: 运用和学习PHP有多难 Nächster Artikel: 自个儿创建PHP模板系统