php.net |  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
Votes:4
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dennispopel at lycos dot com
New email:
PHP Version: OS:

 

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

Funny logical error:

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

then
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
UnSet($x[0])

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

<?php
error_reporting(E_ALL);
$x = array(1);
echo "Count: " . count($x) . "\n";
unset($x[0]);
echo "Count: " . count($x) . "\n";
?>

Results:

Count: 1
Count: 0


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


Torben
 [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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC