Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

Install

$ wget http://www.phpdoc.org/phpDocumentor.phar
$ chmod +x phpdocumentor.phar

Let's try a class

$ cat src/Classe.php
<?php

/**
 * Classe.
 */
class Classe {}

$ ./phpdocumentor.phar -f src/Classe.php
Collecting files .. OK
Initializing parser .. OK
Parsing files
blablabla...

All right. But now let's try a function

$ 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...

Now there are errors (Warning). Why?

I also tried installing phpdoc via composer

$ 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

But the result is even worse

$ 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

At this point I would like to know, is this phpdoc a valid tool? Am I the one who can't use it? What's wrong?

like image 260
saven41 Avatar asked Dec 03 '25 16:12

saven41


1 Answers

Those errors are happening because you are calling the count method with a parameter that is not an array or doesn't implement the Countable interface. Prior to PHP 7.2 if you called count(null) the value 0 would be returned and no warning would be issued, after (and including) PHP 7.2 that warning is issued when calling count with an invalid parameter. As you can check here the first parameter must be:

An array or Countable object.

This means that phpdocumentor.phar has some code that is not fully compatible with PHP 7.2+. You can try downgrading the php version or upgrading the phpdocumentar (if possible).

like image 104
Claudio Avatar answered Dec 06 '25 05:12

Claudio