PHPDocumentor 2 and PHP 7 with opcache issues in Doctrine
Asked Answered
B

5

14

Hopefully someone here knows a thing or 2 about this.

Short Question

I am running into an error using phpdoc on the command line, installed via pear on PHP 7.0.2. The error is:

#> 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

How do I fix this error?

Details

Opcache is enabled and opcache.load_comments=1 is in my opcache.ini file, verified by using the commands: php -i | grep "Opcode" and php -i | grep "opcache" respectively. Within that .ini file I can verify that changes are loaded by checking enable and disable opcache via that file.

With that said, if I have opcache.load_comments=1 in my .ini file, why am I still getting this error?

Thanks!

Bellinger answered 23/1, 2016 at 0:46 Comment(0)
I
16

I encountered the same problem while using the PHAR version of PHPDocumentor. The PHAR includes an obsolete version of Doctrine Annotations.

The older version of Annotations is referring to the opcache.load_comments setting in php.ini, which does not exist in PHP 7:

This has been fixed upstream in Annotations:

For now, using the composer version of PHPDocumentor by executing composer require --dev phpdocumentor/phpdocumentor resolved the problem for me.

Isometric answered 23/1, 2016 at 3:50 Comment(1)
Now THAT makes sense. PHP 7 doesn't have that anymore in the ini file, ok that's the reason. Right now I have it setup with PHAR and pecl, so if I use composer (which I have currently) it will install over phpdocumentor in my current used PHP version? Just want to make sure before I put in that command.Bellinger
M
13

You can also use composer without manually switching vendors directory contents. Just use:

composer require doctrine/annotations

to have the latest version of doctrine/annotations (at least 1.2.5 solves the problem)

Ma answered 24/4, 2016 at 11:37 Comment(2)
Worked for me just fine, with Symfony 2.6.Basle
"- Installing doctrine/annotations (v1.4.0)" dsn't work. solved by doctrine annotations patch 1.2.5Solferino
S
7

phpDocumentor 2.8.5 is the default version with Ubuntu 16.04. However, php7 support wasn't added until 2.9. I got it working by using the following on the command line:

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

If you installed phpDocumentor from pear, use the following to remove it:

sudo pear uninstall phpdoc/phpDocumentor
Spinney answered 27/9, 2016 at 17:24 Comment(1)
absolutely best answer so far for devops systems. It does not require running ad-hoc composer commands that pulls 62M of composer source and require deep linking to a final command path. This simple script got me a .phar I could use, put in place that works perfectly with our 7.0.10 docker builds with no problems! Thanks!!Starr
B
4

Thanks deepdivedylan for links. However, composer require --dev phpdocumentor/phpdocumentor did not solve my problem. But reading through the links and downloading doctrine annotations patch 1.2.5 worked fine. Just download archive and replace vendor/doctrine/annotations folder with its contents.

Beseem answered 21/3, 2016 at 19:35 Comment(2)
Fatal error: Uncaught Error: Class 'Doctrine\Common\Annotations\AnnotationRegistry' not found in /home/vasu/work/hosting/prekkha/app/autoload.php:11Solferino
solved. not "replace folder", but "replace content" - mergeSolferino
L
0

You can download the latest version of phar from github releases .

The link from website is to an older version of it.

Leadbelly answered 9/2, 2017 at 4:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.