PHP :: Bug #23769 :: Glob() gives wrong result when pattern not found
- ️Fri May 23 2003
Bug #23769 | Glob() gives wrong result when pattern not found | |||
---|---|---|---|---|
Submitted: | 2003-05-23 04:11 UTC | Modified: | 2003-06-03 06:04 UTC | |
From: | patric at liefdeis dot com | Assigned: | hholzgra (profile) | |
Status: | Closed | Package: | Filesystem function related | |
PHP Version: | 4.3.2 | OS: | FreeBSD | |
Private report: | No | CVE-ID: | None |
[2003-05-23 04:11 UTC] patric at liefdeis dot com
When I do a glob() on my Linux machine with a pattern that doesn't have any hits, I receive an array with 0 entries. This is not the problem. When I do the same on my FreeBSD machine, I get 1 entry which is empty. This is a problem. The FreeBSD machine does run a CVS version of 4.3.0, where the Linux machine is running the 4.3.0 release version. I don't know if that has anything to do with it, or that the problem is OS based. Anywayz, tnx for looking in to it.
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commitsRelated reports
[2003-05-28 06:10 UTC] patric at liefdeis dot com
I can't reproduce the bug in a simple form, nor can I upgrade the FreeBSD machine to a CVS version, so we will wait till the next official PHP version, then I will check again if the problem still exists. What I did notice was, that with PHP 4.3.1, Linux gives an empty array back, where FreeBSD gives nothing back. (print_r(glob("*.doesnotexist"));) Anyway, I will check back in after the next release.
[2003-05-31 05:02 UTC] patric at liefdeis dot com
Okay, I found the problem. Here is an example code: <? echo "a"; $f = glob("*.nothing"); print_r($f); if (is_array($f)) { echo "c"; } echo count($f)."b"; ?> When I look at this, I expect to get: 'a0b'. But I do get: 'a1b' on my FreeBSD 4.3 machine. On my Windows XP machine I get: 'aArray ( ) c0b' That seems more okay. Also under Linux 2.4.18-3 and FreeBSD 4.8 it gives that same result. So I guess it is a typical FreeBSD 4.3 problem. Is it possible to fix this? Tnx anyway!
[2003-06-03 06:02 UTC] hholzgra@php.net
so what you actualy get is a boolean FALSE instead of an empty array() ... (you can see this if you change the print_r() call in your test code to var_dump(), which is more verbose) you can work around this by testing the result with empty(), which returns TRUE for both empty arrays and boolean FALSE values (amongst others) instad of count(), which returns 1 if applied to any variable that is not an array any volunteer who can give me access to a FreeBSD 4.3 system to identify which of the code pathes returning FALSE it actualy runs into here so that we can hopefully fix this and get more consistent behaviour?
[2003-06-03 06:04 UTC] hholzgra@php.net
This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. found and fixed