SV: SV: [PHP4BETA] unset() bug or feature?
| From: | Johan Ekenberg | Date: | Mon, 03 Jan 2000 17:12:03 +0000 |
| Subject: | SV: SV: [PHP4BETA] unset() bug or feature? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-8860@lists.php.net to get a copy of this message | ||
> > Yes. But look at this:
> >
> > $array[0] = "Set";
> > print count($array); // prints: 1
> > unset ($array[0]); // $array
> now contains 0 items.
> > reset($array); // This doesn't help
>
> It doesn't help what?
As far as I understand it doesn't reset the internal
array pointer to $array[0]. If it would,
the subsequent addition to $array[] would be placed
in $array[0] and not $array[1] as is the case.
> > print count($array); // prints: 0
> > $array[] = "Set"; // Add to
> $array (which contains _zero_ items!)
> > print count($array); // prints: 1
> > print "$array[0]"; // prints: (nothing)
> > print "$array[1]"; // prints: Set
> >
> > Questions:
> > 1. Why isn't the internal array pointer reset when any or
> all items are
> > unset()?
>
> Why should it? It should only move if the element being unset is the one
> currently pointed by the internal pointer, and then too it shouldn't
> reset, but move to the next element.
Ok, I won't argue more on that.
> > 2. Why doesn't reset() reset the internal array pointer?
>
> It does. What makes you think it doesn't?
See comment above. $array[] = "Set" adds to $array[1] even though
$array was just reset(). Shouldn't it add to $array[0] ??
/Johan Ekenberg