php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75733 count(null) and count(empty-string) raises a warning
Submitted: 2017-12-26 09:12 UTC Modified: 2017-12-26 10:46 UTC
From: php-bug-reports at protonmail dot com Assigned: cmb (profile)
Status: Closed Package: Arrays related
PHP Version: 7.2.0 OS: Ubuntu, Windows
Private report: No CVE-ID: None
 [2017-12-26 09:12 UTC] php-bug-reports at protonmail dot com
Description:
------------
Since version of PHP 7.2.0 (stable) and 7.2.1 RC1 count() will raise a warning if argument is either null or empty string.

It is hard to file this either as a bug, or documentation problem, because as stated in the manual (here: php.net/manual/en/function.count.php), examples are now obsolete / wrong.

Additionally, in the same page in Changelog it is stated this, which adds even more to the confusion:

Changelog
Version	Description
7.2.0	count() will not yield a warning on invalid countable types passed to the array_or_countable parameter.

Test script:
---------------
$s = '';
echo count($s); // returns 1 with a warning

$n = null;
echo count($n); // returns 0 with a warning

$f = false;
echo count($f); // returns 1 with a warning

Expected result:
----------------
No warnings issued, or update documentation to include warnings issued.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-26 10:09 UTC] requinix@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Variables related +Package: Arrays related
 [2017-12-26 10:09 UTC] requinix@php.net
It is supposed to warn. https://wiki.php.net/rfc/counting_non_countables
 [2017-12-26 10:26 UTC] nikic@php.net
It's a typo, s/not/now :)
 [2017-12-26 10:45 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=343711
Log: Fix #75733: count(null) and count(empty-string) raises a warning
 [2017-12-26 10:46 UTC] cmb@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2017-12-26 10:46 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2017-12-26 13:17 UTC] spam2 at rhsoft dot net
this is clearly a documentation problem

http://php.net/manual/de/migration72.incompatible.php
An E_WARNING will now be emitted when attempting to count() non-countable types (this includes the sizeof() alias function)
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=3fcc64d11680267ea5be82b3e7003f472040d75b
Log: Fix #75733: count(null) and count(empty-string) raises a warning
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 15 21:01:30 2024 UTC