php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #28656 the glob() function does not match the same as shell wildcarding does
Submitted: 2004-06-07 00:33 UTC Modified: 2004-07-03 11:42 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phpbugs at atu dot cjb dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.6 OS: GNU/Linux
Private report: No CVE-ID: None
 [2004-06-07 00:33 UTC] phpbugs at atu dot cjb dot net
Description:
------------
A trailing forward slash is ignored by glob(), but is not with standard UNIX wildcard matching.

ls -lp Dir

drwx------  2 raven users 48 Jun  6 15:26 CSS/
drwx------  2 raven users 48 Jun  6 15:26 Extra/
drwx------  2 raven users 48 Jun  6 15:26 Images/
-rw-------  1 raven users  0 Jun  6 15:26 Main.data
-rw-------  1 raven users  0 Jun  6 15:26 index.php

echo Dir/*/

Dir/CSS/ Dir/Extra/ Dir/Images/

Reproduce code:
---------------
foreach (glob("Dir/*/") as $Dir) { echo "$Dir "; }


Expected result:
----------------
Dir/CSS/ Dir/Extra/ Dir/Images/

Actual result:
--------------
Dir/CSS/ Dir/Extra/ Dir/Images/ Dir/Main.data Dir/index.php

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-07 15:53 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

glob() function returns the same output as the glob() libc 
function. The output of ls is something different and 
unrelated. 
 [2004-06-08 04:55 UTC] phpbugs at atu dot cjb dot net
"The glob() function searches for all the pathnames matching pattern according to the rules used by the shell. No tilde expansion or parameter substitution is done."

This is from the manual page on php.net, but it is not correct.  The example I gave has nothing at all to do with "ls", as iliaa suggested.  It is "matching pattern according to the rules used by the shell", exactly as the description states.  Go to a shell and type in the command I said:

echo Dir/*/

That is pure shell wildcard expansion -- nothing to do with ls or any other shell command.  Clearly globbing "*/" should not match "*" as it currently does, if the objective is to use standard UNIX wildcard expansion.
 [2004-06-08 05:27 UTC] iliaa@php.net
glob() works just like the underlying C function on which 
it is based. If you do not like that complain to libc 
developers. 
 [2004-06-08 06:48 UTC] phpbugs at atu dot cjb dot net
Then the web site and manual pages should be updated so they display correct information.  Currently it states:

"The glob() function searches for all the pathnames matching pattern according to the rules used by the SHELL."

When in fact it is using the rules of the C function glob(), not the UNIX shell.  The description needs to be fixed.  I am not complaining about the way it is implimented, I am complaining about the *description* being wrong.
 [2004-06-08 10:01 UTC] derick@php.net
That makes it a documentation problem.
 [2004-07-03 11:42 UTC] et@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:12 UTC] phpdocbot@php.net
Automatic comment on behalf of et
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a71ac4c538df86c75e5bf93a2ea6eb98d1290b84
Log: fix #28656
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Aug 22 14:01:27 2024 UTC