phpdoc:PHP警告:count():参数必须是实现可计数的数组或对象

phpdoc:PHP警告:count():参数必须是实现可计数的数组或对象,php,Php,安装 让我们试着上一节课 $ wget http://www.phpdoc.org/phpDocumentor.phar $ chmod +x phpdocumentor.phar 但结果更糟 $ composer require --dev phpDocumentor/phpDocumentor blablabla... Package kherge/version is abandoned, you should avoid using it. No replacement was sug

安装

让我们试着上一节课

$ wget http://www.phpdoc.org/phpDocumentor.phar
$ chmod +x phpdocumentor.phar
但结果更糟

$ 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
在这一点上,我想知道,这个phpdoc是一个有效的工具吗? 是我不能用的吗?
怎么了?

发生这些错误是因为您使用的参数不是数组或未实现
可数
接口调用
计数
方法。在PHP7.2之前,如果调用
count(null)
将返回值0,并且不会发出警告,在PHP7.2之后(包括PHP7.2),当使用无效参数调用
count
时会发出警告。正如您可以检查的那样,第一个参数必须是:

数组或可数对象

这意味着
phpdocumentor.phar
有一些代码与PHP7.2+不完全兼容。您可以尝试降级php版本或升级
phpdocumentar
(如果可能)。

++composer require--dev phpdocumentor/phpdocumentor dev master
./composer.json已更新
使用包信息加载composer存储库
更新依赖项(包括需要开发人员)
没有要安装或更新的内容
生成自动加载文件
++php-v
PHP 7.2.19-0ubuntu0.19.04.2(cli)(构建时间:2019年8月13日11:45:23)(新南威尔士州)
版权所有(c)1997-2018 PHP集团
Zend Engine v3.2.0,版权所有(c)1998-2018 Zend Technologies
Zend OPcache v7.2.19-0ubuntu0.19.04.2,版权所有(c)1999-2018,由Zend Technologies提供
++cat src/Assembler.php

除了问题中提到的错误之外,我也遇到了这个错误。。。难以置信的
$ 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 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
++ 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