|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16045 count($array) logical error
Submitted: 2002-03-13 15:11 UTC Modified: 2002-05-05 00:00 UTC
Avg. Score:1.5 ± 0.9
Reproduced:1 of 4 (25.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dennispopel at lycos dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 4.1.1 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dennispopel at lycos dot com
New email:
PHP Version: OS:


 [2002-03-13 15:11 UTC] dennispopel at lycos dot com

Funny logical error:

if we have a simple variable, say
$x = 1

count($x) == 1, which is "natural" (I don't think so)

And if we have an array
$x[0] = 1;
count($x) == 1,

but after

we still have
count($x) = 1!

This leads to a very special kind of logical errors which are really hard to track.

My suggestion:
either: introduce explicit type system (with unions, structs and arrays ;)
or: disable count on variables


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-13 15:45 UTC]
FWIW, I used the following script and got the correct 

$x = array(1);
echo "Count: " . count($x) . "\n";
echo "Count: " . count($x) . "\n";


Count: 1
Count: 0

This is on version 4.2.0-dev. and 4.1.2. What does this
script produce for you?

 [2002-05-05 00:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 21:01:28 2024 UTC