PHP 4.0 Bug #6507 Updated: in_array never returns a proper value

From: Date: Sat, 16 Sep 2000 21:55:52 +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-33384@lists.php.net to get a copy of this message
ID: 6507 Updated by: stas Reported By: darron@froese.org Status: Closed Bug Type: *General Issues Assigned To: Comments: When you use prev() just after reset(), you get no value - that's OK, because reset() makes array pointer to point to the first element. You cannot use next() after that too, without reset(), because array pointer is not valid anymore. You need to check that prev() failed and do the reset(). Previous Comments: --------------------------------------------------------------------------- [2000-09-16 10:10:21] darron@froese.org I tried this again on another server - it's a Mandrake 7.0 box. I recompiled Apache with this configure line: ./configure --prefix=/usr/local/apache --enable-module=so Then I compiled php-4.0.0 with this line and tested: ./configure --with-apxs=/usr/local/apache/bin/apxs The code that I posted before worked just fine with php-4.0.0. It's been posted here: <http://gateway.javelindigital.com/test.phps> <http://gateway.javelindigital.com/test.php> I just grabbed the CVS code (8PM MST 09/16/2000) for php4 and recompiled the module with this configure line: ./configure --with-apxs=/usr/local/apache/bin/apxs Now that I've upgraded to 4.0.3-dev, the code doesn't work. This is the 4th machine I've tested this on: <http://froese.org/~darron/test.php> <http://www.gary-campbell.com/test.php> <http://www.educ8r.net/~darron/test.php> <http://gateway.javelindigital.com/test.php> Only the machine with php-4.0.0 works - the rest all fail. --------------------------------------------------------------------------- [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. --------------------------------------------------------------------------- [2000-09-03 00:08:43] darron@froese.org This script works just fine in PHP 4.0.0 but fails in 4.0.1pl2, 4.0.2, PHP from CVS as of 8PM 09/02/2000. It's online and works here: PHP 4.0.0 <http://www.gary-campbell.com/test.php> Mandrake 7.0, Apache 1.3.12, Compiled as a DSO. It fails on this machine: PHP 4.0.2-cvs <http://www.educ8r.net/~darron/test.php> Mandrake 7.1, Apache 1.3.12, Compiled as a DSO. I tried it on a machine just now with the CVS version of PHP and it still fails. I've also tried it on a 4.0.2-release machine - it fails there too. <? for ($counter = 0; $counter < 11; $counter++) { $items[$counter] = $counter; } for ($counter = 0; $counter < 11; $counter++) { print "$counter = $items[$counter]<BR>n"; } print "<P>"; for ($counter = 0; $counter < 11; $counter++) { print "$counter = $items[$counter]<BR>n"; 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 ($prev_item) { print "Prev Item Exists<BR>n"; } else { print "Prev Item Does NOT Exist<BR>n"; } if ($next_item) { print "Next Item Exists<BR>n"; } else { print "Next Item Does NOT Exist<P>n"; } } ?> The php-4.0.0 was compiled with: ./configure --with-apxs=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql-prod --with-pdflib --enable-ftp --with-ldap --with-imap=../imap-4.5 --with-zlib --with-jpeg-dir=/usr/lib --with-tiff-dir=/usr/lib --with-zlib-dir=/usr/lib --with-png-dir=/usr/lib --with-gd --with-ttf --with-xml --enable-trans-sid --enable-track-vars=yes --enable-magic-quotes=yes The php-4.0.2 was compiled with: ./configure --with-apxs=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql-prod --with-pdflib --enable-ftp --with-ldap --with-imap=../imap-4.5 --with-zlib --with-jpeg-dir=/usr/lib --with-tiff-dir=/usr/lib --with-zlib-dir=/usr/lib --with-png-dir=/usr/lib --with-gd --with-ttf --with-xml --enable-trans-sid --enable-track-vars=yes --enable-magic-quotes=yes --------------------------------------------------------------------------- The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online. Full Bug description available at: http://bugs.php.net/?id=6507

« previous php.dev (#33384) next »