为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
aluckdog 2022-01-14 16:07:13
安装$ wget http://www.phpdoc.org/phpDocumentor.phar$ chmod +x phpdocumentor.phar让我们试一堂课$ cat src/Classe.php<?php/** * Classe. */class Classe {}$ ./phpdocumentor.phar -f src/Classe.phpCollecting files .. OKInitializing parser .. OKParsing filesblablabla...好的。但是现在让我们尝试一个函数$ cat src/fun.php<?php/** * Summary fun.php *//** * Function. */function fun() {}$ ./phpdocumentor.phar -f src/fun.phpCollecting files .. OKInitializing parser .. OKParsing filesblablabla...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 1293PHP 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 1293PHP 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 1293PHP 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 1293blablabla...现在有错误(警告)。为什么?此时我想知道,这个 phpdoc 是一个有效的工具吗?是我不能用吗?怎么了?
查看完整描述

2 回答

?
忽然笑

TA贡献1806条经验 获得超5个赞

++ 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_VARIABLE 未找到此文件的摘要


php 7.2 和 phpdoc 有没有可能真的不能达成一致?是否有任何与 php 7.2 兼容的 phpdoc 版本?


查看完整回答
反对 回复 2022-01-14
?
皈依舞

TA贡献1851条经验 获得超3个赞

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

一个数组或 Countable 对象。

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


查看完整回答
反对 回复 2022-01-14
  • 2 回答
  • 0 关注
  • 356 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信