Bug #16045 Updated: count($array) logical error
| From: | php-bugs at lists dot php dot net | Date: | Sun, 05 May 2002 04:00:04 +0000 |
| Subject: | Bug #16045 Updated: count($array) logical error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-6935@lists.php.net to get a copy of this message | ||
ID: 16045
Updated by: php-bugs@lists.php.net
Reported By: dennispopel@lycos.com
-Status: Feedback
+Status: No Feedback
Bug Type: *General Issues
Operating System: All
PHP Version: 4.1.1
New Comment:
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".
Previous Comments:
------------------------------------------------------------------------
[2002-03-13 15:45:18] 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-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