Bug #16045 Updated: count($array) logical error
| From: | torben@php.net | Date: | Wed, 13 Mar 2002 20:45:19 +0000 |
| Subject: | Bug #16045 Updated: count($array) logical error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-2409@lists.php.net to get a copy of this message | ||
ID: 16045
Updated by: torben@php.net
Reported By: dennispopel@lycos.com
-Status: Open
+Status: Feedback
Bug Type: *General Issues
Operating System: All
PHP Version: 4.1.1
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2002-03-13 15:11:08] dennispopel@lycos.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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=16045&edit=1