【发布时间】:2016-01-05 07:25:37
【问题描述】:
出现错误:
在 C:\wamp\www\New folder\index.php 中找不到类“位置” 线……
项目文件位置:http://localhost/New%20folder/ 这里类文件和索引文件都保存了。
类文件:location.class.php
class location
{
function add_location()
{
echo 'Its working!';
}
}
我的代码(index.php 根目录下的文件)
<?php
function __autoload($class_name) {
if (file_exists($class_name . '.class.php'))
{
require_once ($class_name . '.class.php');
}
}
try {
$location = new location();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
<html>
<head>
<title>Autoload Testing</title>
</head>
<body>
</body>
</html>
【问题讨论】:
-
我尝试了相同的代码及其工作。你用的是什么版本的php?
-
PHP 版本:5.5.12
-
我使用的是 5.5.11,它工作正常。
-
哦...我尝试了太多次...但它不起作用。
-
autoload 函数实际上是获取文件...我使用 file_exist 检查文件是否存在于该特定目录中。我也使用 else 块...