【发布时间】:2016-08-04 08:46:33
【问题描述】:
我基本上有以下目录结构
- 迷你爬虫
- 脚本/
- htmlCrawler.php
- index.php
- 脚本/
这是 index.php
use Scripts\htmlCrawler;
class Main
{
public function init()
{
$htmlCrawler = new htmlCrawler();
$htmlCrawler->sayHello();
}
}
$main = new Main();
$main->init();
这是 /Scripts/htmlCrawler.php
namespace Scripts;
class htmlCrawler
{
public function sayHello()
{
return 'sfs';
}
}
代码抛出如下错误
致命错误:在中找不到类 'Scripts\htmlCrawler' /mnt/htdocs/Spielwiese/MiniCrawler/index.php 第 9 行
【问题讨论】:
-
您是否在
index.php文件中的任何位置包含/Scripts/htmlCrawler.php? -
@AntoineB 如果我使用 include('Scripts/htmlCrawler.php');但这不会破坏 use 语句的目的吗?例如 Symfony 类只使用 'use' 语句,而不包括 eachother 中的文件
-
我在回答中详细说明了一切:)
标签: php namespaces php-5.5