安装
$ wget http://www.phpdoc.org/phpDocumentor.phar
$ chmod +x phpdocumentor.phar
让我们试着上一节课
$ cat src/Classe.php
<?php
/**
* Classe.
*/
class Classe {}
$ ./phpdocumentor.phar -f src/Classe.php
Collecting files .. OK
Initializing parser .. OK
Parsing files
blablabla...
好吧但是现在让我们尝试一个函数
$ cat src/fun.php
<?php
/**
* Summary fun.php
*/
/**
* Function.
*/
function fun() {}
$ ./phpdocumentor.phar -f src/fun.php
Collecting files .. OK
Initializing parser .. OK
Parsing files
blablabla...
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
Execute transformation using writer "twig"
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
Execute transformation using writer "twig"
Execute transformation using writer "twig"
Execute transformation using writer "twig"
Execute transformation using writer "twig"
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
blablabla...
现在有错误(警告)。为什么啊?
我还尝试通过composer安装phpdoc
$ composer require --dev phpDocumentor/phpDocumentor
blablabla...
Package kherge/version is abandoned, you should avoid using it. No replacement was suggested.
Package herrera-io/json is abandoned, you should avoid using it. Use kherge/json instead.
Package herrera-io/phar-update is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
但结果更糟
$ vendor/bin/phpdoc -f src/Classe.php
PHP Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@JMS\Serializer\Annotation\Type" in property phpDocumentor\Configuration::$title does not exist, or could not be auto-loaded. in vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
Stack trace:
#0 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(741): Doctrine\Common\Annotations\AnnotationException::semanticalError('The annotation ...')
#1 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(663): Doctrine\Common\Annotations\DocParser->Annotation()
#2 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(354): Doctrine\Common\Annotations\DocParser->Annotations()
#3 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php(254): Doctrine\Common\Annotations\Doc in vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 54
在这一点上,我想知道,这个phpdoc是一个有效的工具吗?是我不能用的吗?发生了什么?
++ composer require --dev phpdocumentor/phpdocumentor dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
++ php -v
PHP 7.2.19-0ubuntu0.19.04.2 (cli) (built: Aug 13 2019 11:45:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.19-0ubuntu0.19.04.2, Copyright (c) 1999-2018, by Zend Technologies
++ cat src/Assembler.php
<?php
/**
* File summary.
*/
namespace Xyz;
/**
* @package Abc
*/
class Assembler {
function assemble(?string $string) {
}
}
++ php vendor/bin/phpdoc -f src/Assembler.php --template=responsive
Collecting files .. OK
Initializing parser .. OK
Parsing files
Parsing /mnt/shared-ntfs/Downloads/test-phpdoc/src/Assembler.php
Parse Error: Syntax error, unexpected '?', expecting T_VARIABLE on line 13 No summary was found for this file
Storing cache in "/mnt/shared-ntfs/Downloads/test-phpdoc/output/build" .. OK
Load cache .. 0.001s
Preparing template "responsive" .. 0.006s
Preparing 13 transformations .. 0.000s
Build "elements" index .. 0.000s
Replace textual FQCNs with object aliases .. 0.000s
Resolve @link and @see tags in descriptions .. 0.000s
Enriches inline example tags with their sources .. 0.000s
Build "packages" index .. 0.001s
Build "namespaces" index and add namespaces to "elements" .. 0.000s
Collect all markers embedded in tags .. 0.000s
Transform analyzed project into artifacts ..
Applying 13 transformations
Initialize writer "phpDocumentor\Plugin\Core\Transformer\Writer\FileIo"
Initialize writer "phpDocumentor\Plugin\Core\Transformer\Writer\Xml"
Initialize writer "phpDocumentor\Plugin\Core\Transformer\Writer\Xsl"
Initialize writer "phpDocumentor\Plugin\Graphs\Writer\Graph"
Execute transformation using writer "FileIo"
Execute transformation using writer "FileIo"
Execute transformation using writer "FileIo"
Execute transformation using writer "xml"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "xsl"
Execute transformation using writer "Graph"
0.133s
Analyze results and write report to log .. 0.000s
分析错误:语法错误,意外的“?”,第13行应为T_变量。未找到此文件的摘要
有没有可能PHP 7.2和phpdoc不能真正同意?是否有任何phpdoc版本与php 7.2兼容?
发生这些错误的原因是,您正在使用非数组的参数调用count
方法,或者没有实现Countable
接口。在PHP7.2之前,如果调用count(null)
将返回值0,并且不会发出警告,在PHP7.2之后(包括PHP7.2),当使用无效参数调用count
时会发出警告。正如您可以在此处检查的那样,第一个参数必须是:
数组或可数对象。
这意味着phpdocumentor.phar
有一些代码与PHP7.2不完全兼容。您可以尝试降级php版本或升级phpdocumentar
(如果可能)。
我已经迁移到一个使用PHPV7(从我的PHPV5.4)的新服务器上,现在我的网站上显示错误。 这是返回错误的代码行: 我如何解决这个问题?
我将我的Wordpress站点从PHP 5.6更新到7.2,并注意到更新后我的Wordpress后端出现错误。它说: 我已经包括了那一行和下面两行的代码。任何帮助都将不胜感激。
嘿,朋友们,我需要一个解决方案来修复这个错误 警告:sizeof():参数必须是在第18行的C:\xampp\htdocs\my site\wp content\themes\kingdom\woocmerce\content-single-product.php中实现可数的数组或对象 PHP文件的行:
我面临着奇怪的案子。我在生产环境中面临一个错误,而在开发中它工作正常。 开发: Laravel 5.4.28 PHP 7.0.13 MYSQL 5.7.17 制作:Laravel 5.4.28 PHP 7.2.1 MYSQL 5.7.20 在实现代码中。我用过: 在开发中,它运行良好。但是在生产中,它给我这个错误:Count():参数必须是一个数组或一个在Builder.php中实现可数的对象(第
PHP警告:count():参数必须是在/opt/lampp/htdocs/deingreidcht/typo3conf/ext/toctoc\u comments/pi1/class.toctoc\u comments\u pi1.PHP中实现可数的数组或对象如何解决此问题 这是我的代码,我申请了条件,
我更新到PHP7.2,它创建了一个问题数组(没有双关语)。我已经消除了这些警告(主要是sizeof和count()警告。我们有一个错误: 警告:sizeof():参数必须是在第236行的/usr/www/domain/phpmyd/includes/class_registry.php中实现可数的数组或对象 我试着这样修复它: