phpDocumentor version 2.8.5 の PHP7対応

phpDocumentor version 2.8.5 の PHP7対応時に嵌った&修正した項目を荒くメモしておく
とりあえず、動くようにしただけなので、全ての環境で動くわけではない

インストールは下記で実施


pear channel-discover pear.phpdoc.org
pear install phpdoc/phpDocumentor

実行時に結果を置くディレクトリを空にしておかないと Segmentation fault が発生する


rm -rf /home/hoge/phpdoc/htdocs/*



PHP7では opcache.load_comments の設定が無効なので、下記のエラーが起こる
ini_get('opcache.load_comments') の結果が 0 なのか NULL なのか厳密に判別してないため、エラーになる模様


[root@dev htdocs]# phpdoc -d /home/hoge/libphp/API/ -t /home/hoge/phpdoc/htdocs/
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/lib64/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:193
Stack trace:
#0 /usr/local/lib64/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php(171): Doctrine\Common\Annotations\AnnotationException::optimizerPlusLoadComments()
#1 /usr/local/lib64/php/phpDocumentor/vendor/jms/serializer/src/JMS/Serializer/SerializerBuilder.php(338): Doctrine\Common\Annotations\AnnotationReader->__construct()
#2 /usr/local/lib64/php/phpDocumentor/src/Cilex/Provider/JmsSerializerServiceProvider.php(73): JMS\Serializer\SerializerBuilder->build()
#3 /usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php(126): Cilex\Provider\JmsSerializerServiceProvider->Cilex\Provider\{closure}(Object(phpDocumentor\Application))
#4 /usr/local/lib64/php/phpDocumentor/vendor/pimple/pi in /usr/local/lib64/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 193

Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1. in /usr/local/lib64/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 193

Doctrine\Common\Annotations\AnnotationException: You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1. in /usr/local/lib64/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 193

Call Stack:
0.0002 355064 1. {main}() /usr/local/bin/phpdoc:0
0.0004 371048 2. phpDocumentor\Bootstrap->initialize() /usr/local/bin/phpdoc:23
0.0060 1642536 3. phpDocumentor\Application->__construct() /usr/local/lib64/php/phpDocumentor/src/phpDocumentor/Bootstrap.php:62
0.0067 1682552 4. phpDocumentor\Application->addLogging() /usr/local/lib64/php/phpDocumentor/src/phpDocumentor/Application.php:67
0.0073 1759328 5. Pimple->offsetGet() /usr/local/lib64/php/phpDocumentor/src/phpDocumentor/Application.php:254
0.0073 1759328 6. Pimple::{closure:/usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php:122-130}() /usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php:83
0.0073 1759352 7. phpDocumentor\Configuration\ServiceProvider->phpDocumentor\Configuration\{closure}() /usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php:126
0.0074 1772520 8. Pimple->offsetGet() /usr/local/lib64/php/phpDocumentor/src/phpDocumentor/Configuration/ServiceProvider.php:80
0.0074 1772520 9. Pimple::{closure:/usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php:122-130}() /usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php:83
0.0074 1772544 10. Cilex\Provider\JmsSerializerServiceProvider->Cilex\Provider\{closure}() /usr/local/lib64/php/phpDocumentor/vendor/pimple/pimple/lib/Pimple.php:126
0.0090 2000296 11. JMS\Serializer\SerializerBuilder->build() /usr/local/lib64/php/phpDocumentor/src/Cilex/Provider/JmsSerializerServiceProvider.php:73
0.0093 2060856 12. Doctrine\Common\Annotations\AnnotationReader->__construct() /usr/local/lib64/php/phpDocumentor/vendor/jms/serializer/src/JMS/Serializer/SerializerBuilder.php:338


vi /usr/local/lib64/php/phpDocumentor/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php
L193 近辺


if (extension_loaded('Zend OPcache') && ini_get('opcache.load_comments') == 0) {
throw AnnotationException::optimizerPlusLoadComments();
}

↓↓↓↓↓↓

if (extension_loaded('Zend OPcache') && ini_get('opcache.load_comments') === 0) {
throw AnnotationException::optimizerPlusLoadComments();
}




タイプヒンティング時の厳密な型判定により引っ掛かった?

vi /usr/local/lib64/php/phpDocumentor/vendor/monolog/monolog/src/Monolog/ErrorHandler.php


public function handleException(\Exception $e)

↓↓↓↓↓↓

public function handleException(Exception $e)





http://php.net/manual/ja/migration70.incompatible.php
↑の変数の取り扱いの変更の影響(Changes to the handling of indirect variables, properties, and methods)で、扱いが変わった


下記のようなNoticeが発生し、ドキュメント上に出力される


Notice: Array to string conversion in /usr/local/lib64/php/phpDocumentor/vendor/erusev/parsedown/Parsedown.php on line 1404
... 略 ...
Notice: Undefined property: Parsedown::$Array in /usr/local/lib64/php/phpDocumentor/vendor/erusev/parsedown/Parsedown.php on line 1404
... 略 ...

vi /usr/local/lib64/php/phpDocumentor/vendor/erusev/parsedown/Parsedown.php


if (isset($Element['handler']))
{
$markup .= $this->$Element['handler']($Element['text']);
}

↓↓↓↓↓↓

if (isset($Element['handler']))
{
$handler = $Element['handler'];
$markup .= $this->$handler($Element['text']);
}