简体   繁体   English

在Eclipse Neon PDT上使用Composer PSR-0自动加载器时出现错误“找不到类”

[英]Error “Class not found” using Composer PSR-0 autoloader on Eclipse Neon PDT

I am currently trying to build a new PHP project from scratch (inside a git repository), using Composer (for the very first time), on Eclipse Neon PDT with Composer Eclipse Plugin and EGit . 我当前正在尝试使用Composer(首次)在带有Composer Eclipse PluginEGit的 Eclipse Neon PDT上使用Composer从头开始(在git存储库中)构建一个新的PHP项目。

In order to start with something quite simple, I first installed the well-known library PHP Markdown Lib . 为了从简单开始,我首先安装了著名的库PHP Markdown Lib I think that I had not getting problem for configuring the require setting, as running Composer correctly updates dependencies using: 我认为配置require设置没有问题,因为运行Composer可以使用以下方式正确更新依赖项:

"require" : {
    "php" : ">=5.3",
    "michelf/php-markdown" : "~1.7"
},

As described in the Usage section of the documentation of PHP Markdown Lib, I setup a PSR-0-compatible autoloader in my composer.json and generated the autoload file: 如PHP Markdown Lib文档的“ 用法”部分所述,我在composer.json设置了与PSR-0兼容的自动加载器,并生成了autoload文件:

"autoload" : {
    "psr-0" : {
        "Michelf\\Markdown" : "vendor/michelf/php-markdown/Michelf"
    }
},

On my PHP file, I have simply included the following: 在我的PHP文件中,我仅包含以下内容:

$input = file_get_contents('input.md');
use Michelf\Markdown;
$output = Markdown::defaultTransform($input);

All seem to be correctly recognized by Eclipse Neon: Eclipse Neon似乎可以正确识别所有内容:

  1. the namespace and class rightly appear as autocomplete propositions (first screenshot) namespaceclass正确显示为自动完成命题(第一个屏幕截图)
  2. the library is displayed in the outline of the document as import declarations (second screenshot) 库将在文档的轮廓中显示为导入声明 (第二个屏幕截图)

命名空间类

大纲

But, despite all my testings with these settings, the page is still displaying: 但是,尽管我使用这些设置进行了所有测试,但该页面仍显示:

Fatal error: Class 'Michelf\\Markdown' not found 致命错误:找不到类“ Michelf \\ Markdown”

I have tested other formulations, such as use \\Michelf\\Markdown; 我已经测试了其他公式,例如use \\Michelf\\Markdown; : it is equally recognized by Eclipse Neon (autocomplete feature and document outline, as displayed on previous screenshots), but I still get the fatal error . :Eclipse Neon同样可以识别它(自动完成功能和文档大纲,如先前的屏幕快照所示),但仍然出现致命错误

To ensure the autoload file was updated correctly, I have also executed the CLI dump-autoload command. 为了确保自动加载文件已正确更新,我还执行了CLI dump-autoload命令。 Unfortunately, without more success at this time. 不幸的是,目前还没有成功。

Right now, I suppose this problem seems to be not directly related with PHP Markdown Lib , but that I certainly forgot a step or made a mistake within my settings, which seem to fail to correctly set up the PSR-0 autoloader, even if all seem to be correctly detected by the Eclipse IDE. 现在,我想这个问题似乎与PHP Markdown Lib并没有直接关系 ,但是我当然忘记了设置或在设置中犯了一个错误,即使所有这些都似乎无法正确设置PSR-0自动加载器似乎已被Eclipse IDE正确检测到。

您还记得在文件的开头包含composer autoload吗?

require __DIR__ . '/vendor/autoload.php';

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

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