Bug #76470 [Nab]: count(false)===1
| From: | nikic@php.net | Date: | Wed, 13 Jun 2018 14:16:59 +0000 |
| Subject: | Bug #76470 [Nab]: count(false)===1 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215693@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76470&edit=1
ID: 76470
Updated by: nikic@php.net
Reported by: mordyg at gmail dot com
Summary: count(false)===1
Status: Not a bug
Type: Bug
Package: Variables related
Operating System: N/A
PHP Version: 7.1.18
Block user comment: N
Private report: N
New Comment:
This is not another exception, as an undefined variable access returns NULL. I've removed the
note in http://svn.php.net/viewvc?view=revision&revision=345126,
as it is both redundant and nowadays quite unnecessary.
Previous Comments:
------------------------------------------------------------------------
[2018-06-13 14:05:57] mordyg at gmail dot com
You have 2 exceptions ... why not make it 3?
http://prntscr.com/jui1w0
------------------------------------------------------------------------
[2018-06-13 14:05:20] nikic@php.net
See also https://3v4l.org/WUgRo for why it works like it does.
But as @danack mentioned, this kind of stuff is exactly why count() generates a warning starting
with PHP 7.2.
------------------------------------------------------------------------
[2018-06-13 14:04:13] danack@php.net
This is likely to not be fixed as although it's clearly not great behaviour, it is how it has
been for ages, so fixing it would 'break' lots of 'working' code.
However from PHP 7.2, trying to count a non-countable thing gives a warning notice: https://wiki.php.net/rfc/counting_non_countables
If you have an error handler, that converts all warnings to exceptions, the behaviour is then
acceptable.
------------------------------------------------------------------------
[2018-06-13 14:01:59] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
http://php.net/manual/en/function.count.php
> Returns the number of elements in array_or_countable. When the parameter is neither an array
> nor an object with
> implemented Countable interface, 1 will be returned. There is one exception, if
> array_or_countable is NULL, 0
> will be returned.
------------------------------------------------------------------------
[2018-06-13 13:59:18] mordyg at gmail dot com
Just to clarify ..
count(null) ===0
So if you say this is not a bug as it a non-countable, then you have a new bug, that count(null)
should be 1, not 0
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76470
--
Edit this bug report at https://bugs.php.net/bug.php?id=76470&edit=1