PHP 4.0 Bug #6507 Updated: in_array never returns a proper value
| From: | Bug Database | Date: | Sun, 03 Sep 2000 18:44:58 +0000 |
| Subject: | PHP 4.0 Bug #6507 Updated: in_array never returns a proper value | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-31819@lists.php.net to get a copy of this message | ||
ID: 6507
User Update by: darron@froese.org
Old-Status: Closed
Status: Open
Bug Type: Misbehaving function
Description: in_array never returns a proper value
> before using next, perv and current, you should do reset(). > Then, next and prev not only
> get items, but move array
> pointer. Please read the manual about that.
That's the behaviour you see in php 4.0.0 and the behaviour I'm used to (that's why
there's two times I do "if (in_array("$counter", $items))"). It
doesn't work in anything since then.
This code works just fine in PHP 4.0.0 *with* or *without* the reset($items) - it's online and
working at
<http://gary-campbell.com/test.php>
This code fails under any version of PHP since then on multiple machines. It's online and
failing at
<http://www.educ8r.net/~darron/test3.php>
Here's the code:
<?
for ($counter = 1; $counter < 11; $counter++) {
$items[$counter] = $counter;
}
for ($counter = 1; $counter < 11; $counter++) {
print "$counter = $items[$counter]<BR>\n";
}
print "<P>";
for ($counter = 1; $counter < 11; $counter++) {
print "$counter = $items[$counter]<BR>\n";
reset($items);
if (in_array("$counter", $items)) {
$current_item = current($items);
$previous_item = prev($items);
print "Current: $current_item<BR>\n";
print "Previous: $previous_item<BR>\n";
}
if (in_array("$counter", $items)) {
$next_item = next($items);
print "Next: $next_item<BR>\n";
}
if ($previous_item) {
print "Prev Item Exists<BR>\n";
} else {
print "Prev Item Does NOT Exist<BR>\n";
}
if ($next_item) {
print "Next Item Exists<P>\n";
} else {
print "Next Item Does NOT Exist<P>\n";
}
}
?>
Previous Comments:
[2000-09-03 14:44:58] darron@froese.org
> before using next, perv and current, you should do reset(). > Then, next and prev not only
> get items, but move array
> pointer. Please read the manual about that.
That's the behaviour you see in php 4.0.0 and the behaviour I'm used to (that's why
there's two times I do "if (in_array("$counter", $items))"). It
doesn't work in anything since then.
This code works just fine in PHP 4.0.0 *with* or *without* the reset($items) - it's online and
working at
<http://gary-campbell.com/test.php>
This code fails under any version of PHP since then on multiple machines. It's online and
failing at
<http://www.educ8r.net/~darron/test3.php>
Here's the code:
<?
for ($counter = 1; $counter < 11; $counter++) {
$items[$counter] = $counter;
}
for ($counter = 1; $counter < 11; $counter++) {
print "$counter = $items[$counter]<BR>n";
}
print "<P>";
for ($counter = 1; $counter < 11; $counter++) {
print "$counter = $items[$counter]<BR>n";
reset($items);
if (in_array("$counter", $items)) {
$current_item = current($items);
$previous_item = prev($items);
print "Current: $current_item<BR>n";
print "Previous: $previous_item<BR>n";
}
if (in_array("$counter", $items)) {
$next_item = next($items);
print "Next: $next_item<BR>n";
}
if ($previous_item) {
print "Prev Item Exists<BR>n";
} else {
print "Prev Item Does NOT Exist<BR>n";
}
if ($next_item) {
print "Next Item Exists<P>n";
} else {
print "Next Item Does NOT Exist<P>n";
}
}
?>
----------------------------------------------------------------------------
[2000-09-03 06:01:20] stas@php.net
before using next, perv and current, you should do reset(). Then, next and prev not only get items,
but move array pointer. Please read the manual about that.
----------------------------------------------------------------------------
[2000-09-03 00:24:00] darron@froese.org
Sorry, the description is wrong - in_array still seems to be working, it's current($array),
prev($array) and next($array) that seem to be misbehaving.
----------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=6507