gpt4 book ai didi

php文档 : PHP Warning: count(): Parameter must be an array or an object that implements Countable

转载 作者:行者123 更新时间:2023-12-05 07:19:07 24 4
gpt4 key购买 nike

安装

$ 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 是一个有效的工具吗?我是不会用的人吗?怎么了?

最佳答案

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

An array or Countable object.

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

关于php文档 : PHP Warning: count(): Parameter must be an array or an object that implements Countable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57978059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com