简体   繁体   English

PHP:PHP找不到在include()脚本中定义的类

[英]PHP: php can't find a class defined in an include() script

I am trying to use Michelf's PHP implementation of Markdown. 我正在尝试使用Markdown的Michelf的PHP实现。

I'm including his Markdown.php script with include() at the beginning of my main script, but when trying to use the class (be it for creating a new object or using a method directly), I get this: 在主脚本的开头,我将他的Markdown.php脚本包含在include()中,但是当尝试使用该类时(无论是用于创建新对象还是直接使用方法),我都会得到:

Fatal error: Class 'Markdown' not found in [my main script] 致命错误:在[我的主脚本]中找不到类'Markdown'

The class Markdown is cleary defined in included Markdown.php however. 但是,在包含的Markdown.php中明确定义了Markdown类。

I've checked, of course, that the include works. 当然,我已经检查了include的工作原理。 I've tried placing Markdown.php in both my include_path and my main script's path, it doesn't change anything. 我试过将Markdown.php放在我的include_path和主脚本的路径中,它没有任何改变。

I am at a loss. 我很茫然。

Judging by the source file , you most likely forgot to import the class before using it: 源文件来看,您很可能在使用它之前忘记了导入该类:

use Michelf\Markdown;

// ...

$md = new Markdown();

Alternatively, you could use the canonical name: 或者,您可以使用规范名称:

$md = new \Michelf\Markdown();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM