Re: PHP 4.0 Bug #5455 Updated: readdir() still doesn't work
| From: | Zak Greant | Date: | Wed, 06 Sep 2000 22:11:07 +0000 |
| Subject: | Re: PHP 4.0 Bug #5455 Updated: readdir() still doesn't work | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-32468@lists.php.net to get a copy of this message | ||
This bug sounds almost the same as bug 5540.
- Zak
----- Original Message -----
From: "Bug Database" <php-dev@lists.php.net>
To: <php-dev@lists.php.net>
Sent: Wednesday, September 06, 2000 3:50 PM
Subject: [PHP-DEV] PHP 4.0 Bug #5455 Updated: readdir()
still doesn't work
> ID: 5455
> Updated by: sniper
> Reported By: johan@ekenberg.se
> Status: Feedback
> Bug Type: Directory function related
> Assigned To:
> Comments:
>
> You don't use closedir() anywhere in your code.
> Please try this example:
>
> <?php
>
> $dir = opendir(".");
>
> while ($file = readdir($dir)) {
> if ($file != "." && $file != "..") {
> echo "$file<br>";
> }
> }
> closedir($dir);
> ?>
>
> If this doesn't help, upgrade to latest CVS.
> This works just fine for me.
>
> --Jani
>
> Previous Comments:
>
> [2000-09-06 05:08:18] johan@ekenberg.se
> I've still got the problem after upgrade to 4.02.
> System is libc5 (Slackware 4.0) running 2.2.16.
>
> Example code and phpinfo() available here:
> http://www.ekenberg.se/readdir/index.php
>
>
> ----------------------------------------------------------
-----------------
>
> [2000-09-02 20:13:46] sniper@php.net
> Please upgrade to php4.0.2. I just tried your example code
and
> it works just fine for me.
>
> Reopen if problem still persists.
>
> --Jani
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-15 09:53:01] johan@ekenberg.se
> Stefan Kirch [s.kirch at bauer-kirch.de] mailed me:
>
> -- start quote --
> I have the same problem (#5535) and found a "work-around"
like the following:
>
> if (ereg("^foo$", $file)) {
>
> RegEx works fine, so it seems to be a problom of
string-comparison. Codes like
>
> if ($x == "5") {
>
> also breaks the loop, on the other hand, numerical
comparisons like
>
> if ($x == 5) {
>
> works fine.
> -- end quote --
>
> I don't know if this might give any clues to the experts?
>
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-15 05:09:57] johan@ekenberg.se
> 1. The while loop is only evaluated once, despite the fact
that there are more directory entries to list. I earlier
wrote that the while-loop exits at the first evaluation of
the if-statement, but that is not true. The execution
continues after the if-statement until the end of the while
loop, there it exits. If the if-statement is removed or
commented out, the while loop will continue looping until
all entries in the directory are listed. With the
if-statement left in place it's exactly like putting
"break;" as the last line of the while loop - it never
evaluates more than once. I guess that something in the
if-statement makes readdir($dir) evaluate to false the next
time.
>
> $dir = opendir(".");
> while ($file = readdir($dir)) {
> print "<br>$file";
> if ($file == "foo") {
> // anything or nothing here, doesn't matter
> }
> // Code placed here will also be evaluated,
> // but as long as the if-statement above is not
> // removed, the while loop will exit after
> // completing once - like putting a
> // break;
> // as the last line of the while loop.
> }
>
> I earlier submitted an URL with a working example which I
believe displays the issue rather clearly:
http://www.ekenberg.se/readdir/index.php
>
> 2. "gdb -X httpd" doesn't report anything unusual - httpd
happily keeps on executing, there are no errors and it
doesn't exit. zend_bailout() is never called.
>
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-13 04:22:58] stas@cvs.php.net
> What do you mean by "while loop exits"?
> If you run "gdb httpd -X" and then try you script - what
gdb says? Could you also put breakpoint on zend_bailout()
and see if it isn't called from somewhere (and if it is -
from where?)
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-12 05:32:07] johan@ekenberg.se
> As I wrote earlier, the problem is that the while-loop
exits at the first evaluation of the "if-statement", thus
printing only the first directory entry - a dot. If the
"if-statement" is removed or commented out, the complete
directory listing is printed out.
>
> "anything" is just that - anything or nothing. Call it
"bogus", "foo", or remove it completely - it just doesn't
matter.
>
> Enabling debug did not produce any messages in the PHP or
error-logs.
>
> How do I check the exit code? This is run as an Apache
module with no errors produced in the logs - I suppose
that's an exit code of 0?
>
> Please check the following URL for a working example:
> http://www.ekenberg.se/readdir/index.php
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-12 03:04:13] stas@cvs.php.net
> How exactly it doesn't work? What happens if you enable
debug - do some messages appear? What was "anything" in your
script? What is the exit code after exit?
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-11 16:48:54] johan@ekenberg.se
> I've tried the latest CVS as of July 10, and it still
doesn't work. It seems (with pl2 and latest CVS alike) that
it may work once or twice before breaking. Please note that
if the "if-statement" is commented out, the code works fine.
>
> Please let me know if there's anything more I can do to
help!
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-08 12:02:12] stas@cvs.php.net
> Works for me in latest CVS. Could you please try?
>
> ----------------------------------------------------------
-----------------
>
> [2000-07-08 11:53:29] johan@ekenberg.se
> I still experience problems with readdir(), using Apache
1.3.12 and PHP 4.0.1pl2:
>
> The while loop exists at the first evaluation of the
if-statement. If the if-statement is commented out, the code
works.
>
> $dir = opendir(".");
> while ($file = readdir($dir)) {
> print "<br>$file";
> if ($file == "foo") {
> // anything
> }
> }
>
> Config:
> PHP Version 4.0.1pl2
>
> './configure' '--with-apache=../apache_1.3.12'
'--with-mysql' '--with-gd' '--with-ttf' '--with-ftp'
'--with-swf' '--with-mcrypt' '--with-mhash' '--with-xml'
'--disable-posix-threads' '--enable-memory-limit=yes'
'--enable-track-vars' '--enable-debug=no'
>
> ----------------------------------------------------------
-----------------
>
>
> Full Bug description available at:
http://bugs.php.net/?id=5455
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail:
php-dev-help@lists.php.net
> To contact the list administrators, e-mail:
php-list-admin@lists.php.net
>
>