|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
25 + 44 = ?
Subscribe to this entry?

 [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: Fri Apr 12 21:01:30 2024 UTC