Home  >  Article  >  Backend Development  >  php5中_autoload()的步骤为什么不能使用呢

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

WBOY
WBOYOriginal
2016-06-13 13:25:51903browse

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");

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn