php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53460 glob() returns false for a pattern that matches zero files
Submitted: 2010-12-03 05:56 UTC Modified: 2016-09-04 04:22 UTC
Votes:6
Avg. Score:4.5 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:2 (33.3%)
From: cameel2+php at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Filesystem function related
PHP Version: 5.3.3 OS: Arch Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cameel2+php at gmail dot com
New email:
PHP Version: OS:

 

 [2010-12-03 05:56 UTC] cameel2+php at gmail dot com
Description:
------------
On my system the glob() returns false if there are no files matching the pattern even though the documentation (http://php.net/manual/en/function.glob.php) states that it should return an empty array. 

PHP version: 5.3.3

The only things I have changed in php.ini are open_basedir (/srv/http/:/home/:/usr/share/webapps:/etc/webapps:/tmp/:/usr/share/pear/:/usr/share/symfony) and enabling of several extensions (mcrypt, mysql, pdo, pdo_sqlite). 

I've seen similar bugs reported and closed a few years ago: #29928

Test script:
---------------
<?php 
    // phpMyAdmin is an empty, existing directory located in Apache root
    $glob = glob('/phpMyAdmin/*');
    echo $glob == false  ? "false\n" : ""; 
    echo is_array($glob) ? "array\n" : ""; 
?>                           

Expected result:
----------------
glob() should return an empty array if no files match the pattern.

Actual result:
--------------
The script prints 'false' when run on my box (both under Apache 2.2.17 and with php from command line).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-03 12:53 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2010-12-03 12:53 UTC] pajoye@php.net
Are you sure you mean $glob = glob('/phpMyAdmin/*'); and not $glob = glob('phpMyAdmin/*');? The sooner is an absolute path '/phpMyAdmin/', where the 2nd path is relative (to CWD).
 [2010-12-03 17:41 UTC] cameel2+php at gmail dot com
-Status: Feedback +Status: Open
 [2010-12-03 17:41 UTC] cameel2+php at gmail dot com
Yeah, I meant that since I tested it under Apache first and that directory is located in /srv/http, i.e. in the root directory of the server.

But you're right - for php being run from command line I should have used relative path. Still, when I remove the leading slash and run 

cd /srv/http; php test.php

the result is still false.

This is a contrived example anyway. Originally I have noticed it in a more complex path. 

If I do

touch /srv/http/phpMyAdmin/a.file

the script starts printing 'array'.
 [2011-01-09 17:56 UTC] 13550 at free dot fr
"array() == false" is true because array is empty

try var_dump($glob) to be sure that glob does not return an array
 [2011-01-09 18:12 UTC] cameel2+php at gmail dot com
-Package: Filesystem function related +Package: *Directory Services problems
 [2011-01-09 18:12 UTC] cameel2+php at gmail dot com
Right. But in that case the script would be printing both 'false' and 'array'. It prints only 'false'. 

I have just added var_dump() at the end of the test case and now the output is:
false
bool(false)

BTW: I am using PHP 5.3.5 now.
 [2013-10-01 15:52 UTC] mike@php.net
-Status: Open +Status: Feedback -Package: *Directory Services problems +Package: Filesystem function related
 [2013-10-01 15:52 UTC] mike@php.net
Check your open_basedir. Arch has it enabled by default. 

Please enable error_reporting and display_errors before reporting a bug in the future.
 [2013-10-01 16:09 UTC] cameel2+php at gmail dot com
-Status: Feedback +Status: Open
 [2013-10-01 16:09 UTC] cameel2+php at gmail dot com
OK, I'll check that and report back later.

It's been three years and I no longer have PHP and Apache installed. I'll have to set it up again to check this.
 [2016-08-26 14:34 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-08-26 14:34 UTC] cmb@php.net
Any news?
 [2016-09-04 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC