14

希望这里有人对此有所了解。

简短的问题

我在命令行上使用 phpdoc 遇到错误,通过 pear 在 PHP 7.0.2 上安装。错误是:

#> phpdoc
PHP Fatal error:  Uncaught Doctrine\Common\Annotations\AnnotationException: 
You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1. 
in /usr/local/php5-7.0.2-20160108-102134/lib/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:193

如何修复此错误?

细节

Opcache 已启用并且opcache.load_comments=1位于我的 opcache.ini 文件中,分别使用以下命令进行验证:php -i | grep "Opcode"php -i | grep "opcache"。在该 .ini 文件中,我可以通过通过该文件检查启用和禁用 opcache 来验证更改是否已加载。

话虽如此,如果我opcache.load_comments=1的 .ini 文件中有,为什么我仍然会收到此错误?

谢谢!

4

5 回答 5

16

我在使用 PHAR 版本的 PHPDocumentor 时遇到了同样的问题。PHAR 包括一个过时的 Doctrine Annotations 版本。

旧版本的 Annotations 是指 中的opcache.load_comments设置php.ini,在 PHP 7 中不存在:

这已在 Annotations 的上游修复:

现在,通过执行使用 PHPDocumentor 的 Composer 版本composer require --dev phpdocumentor/phpdocumentor解决了我的问题。

于 2016-01-23T03:50:47.243 回答
13

您也可以使用 composer 而无需手动切换供应商目录内容。只需使用:

composer require doctrine/annotations

拥有最新版本的学说/注释(至少 1.2.5 解决了问题)

于 2016-04-24T11:37:02.343 回答
7

phpDocumentor 2.8.5 是 Ubuntu 16.04 的默认版本。但是,直到 2.9 才添加 php7 支持。我通过在命令行上使用以下命令使其工作:

sudo apt-get install php7.0-mbstring
wget https://github.com/phpDocumentor/phpDocumentor2/releases/download/v2.9.0/phpDocumentor.phar
chmod +x phpDocumentor.phar
sudo mv phpDocumentor.phar /usr/local/bin/phpDocumentor-2.9.phar
sudo ln -s /usr/local/bin/phpDocumentor-2.9.phar /usr/local/bin/phpdoc

如果您从 pear 安装了 phpDocumentor,请使用以下命令将其删除:

sudo pear uninstall phpdoc/phpDocumentor
于 2016-09-27T17:24:13.183 回答
4

感谢 deepdivedylan 的链接。但是,composer require --dev phpdocumentor/phpdocumentor并没有解决我的问题。但是通读链接并下载1.2.5 教义注释补丁工作正常。只需下载存档并用其内容替换 vendor/doctrine/annotations 文件夹。

于 2016-03-21T19:35:34.913 回答
0

您可以从github 版本下载最新版本的 phar 。

来自网站的链接指向它的旧版本。

于 2017-02-09T04:46:12.940 回答