尝试自动加载类时出现此错误
尝试自动加载类时出现此错误。
我在 myclass.php 文件中声明这个类,并在 test.php 中实例化它。但我在 xammp 上遇到类未找到错误。 php.ini中的_autoload函数区分大小写吗?
class MyClass {
//some properties and methods
}
function __autoload($class_name) {
require_once($class_name.".php");
}
$myclass = new MyClass();
有人知道问题是什么吗?
I get this error when trying to autoload classes.
I declare this class in myclass.php file and instantiate it in test.php. but i got class not found error on xammp. Is _autoload function case sensitive in php.
class MyClass {
//some properties and methods
}
function __autoload($class_name) {
require_once($class_name.".php");
}
$myclass = new MyClass();
Anyone know what the problem is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您在
myclass.php
中正确定义了MyClass
。您的问题不是由__autoload
引起的,因为错误是class not find
而不是file not find
,如果失败,require_once
会抛出。Make sure you define
MyClass
correctly in yourmyclass.php
.Your problem is not caused by__autoload
because the error isclass not found
instead offile not found
whichrequire_once
would throw out if it fails.PHP 中的类名和函数名不区分大小写,但您的自动加载器在使用
require*
或include*
时必须使用正确的大小写,因为您的操作系统文件系统可能会区分大小写 -敏感的。如果您的自动加载器使用相对路径,请确保调用的类位于 PHP 的include_path
中。Class names and function names in PHP are not case-sensitive, but your autoloader must use the correct case when using
require*
orinclude*
because your OS filesystem may be case-sensitive. And if your autoloader uses relative paths, make sure the classes invoked are in PHP'sinclude_path
.