尝试自动加载类时出现此错误

发布于 2024-10-03 23:32:34 字数 314 浏览 0 评论 0原文

尝试自动加载类时出现此错误。

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一人独醉 2024-10-10 23:32:34

确保您在 myclass.php 中正确定义了 MyClass。您的问题不是由 __autoload 引起的,因为错误是 class not find 而不是 file not find ,如果失败, require_once 会抛出。

Make sure you define MyClass correctly in your myclass.php.Your problem is not caused by __autoload because the error is class not found instead of file not found which require_once would throw out if it fails.

羁拥 2024-10-10 23:32:34

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* or include* because your OS filesystem may be case-sensitive. And if your autoloader uses relative paths, make sure the classes invoked are in PHP's include_path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文