【问题标题】:PHPDocumentor 2 and PHP 7 with opcache issues in DoctrinePHPDocumentor 2 和 PHP 7 在 Doctrine 中存在 opcache 问题
【发布时间】:2016-04-29 17:43:55
【问题描述】:

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

小问题

我在命令行上使用 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 来验证是否加载了更改。

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

谢谢!

【问题讨论】:

    标签: php phpdoc php-7 opcache phpdocumentor2


    【解决方案1】:

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

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

    这已在 Annotations 上游修复:

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

    【讨论】:

    • 现在说得通了。 PHP 7 在 ini 文件中不再有这个了,这就是原因。现在我用 PHAR 和 pecl 设置了它,所以如果我使用 composer(我目前有)它会在我当前使用的 PHP 版本中安装在 phpdocumentor 上?只是想在我输入那个命令之前确定一下。
    【解决方案2】:

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

    composer require doctrine/annotations
    

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

    【讨论】:

    • 用 Symfony 2.6 为我工作得很好。
    • "- 安装学说/注释 (v1.4.0)" dsn 不起作用。由学说注释补丁 1.2.5 解决
    【解决方案3】:

    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
    

    【讨论】:

    • 迄今为止对于 devops 系统的绝对最佳答案。它不需要运行可提取 62M 作曲家源的临时作曲家命令,也不需要深度链接到最终命令路径。这个简单的脚本为我提供了一个我可以使用的 .phar,它可以完美地与我们的 7.0.10 docker 构建完美配合,没有任何问题!谢谢!!
    【解决方案4】:

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

    【讨论】:

    • 致命错误:未捕获的错误:在 /home/vasu/work/hosting/prekkha/app/autoload.php:11 中找不到类 'Doctrine\Common\Annotations\AnnotationRegistry'
    • 已解决。不是“替换文件夹”,而是“替换内容”——合并
    【解决方案5】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2016-06-24
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      相关资源
      最近更新 更多