php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44987 SplFileObject::getRealPath() returns false although file is found by the ctor
Submitted: 2008-05-13 22:52 UTC Modified: 2008-05-20 21:49 UTC
From: ionut dot stan at yahoo dot com Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.2.6 OS: Windows XP, Ubuntu 8.04
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: ionut dot stan at yahoo dot com
New email:
PHP Version: OS:

 

 [2008-05-13 22:52 UTC] ionut dot stan at yahoo dot com
Description:
------------
If SplFileObject is instantiated with the third parameter (search include_path) set to true:

$file = new SplFileObject($filename, 'r', true);

and the file is indeed on path and found,
a consequent call to $file->getRealPath() returns false,
as if the file hasn't been found at all, instead of returning the real path.

Reproduce code:
---------------
/wwwroot
  |
  |-> /directory
  |    |
  |    |-> testfile.txt
  |
  |-> test.php


In test.php:

<?php

set_include_path(dirname(__FILE__) . '/directory');

try {

    $file = new SplFileObject('testfile.txt', 'r', true);
    var_dump($file->getRealPath());
    
} catch (RuntimeException $e) {
    echo 'File does not exist';
}


try {

    $file = new SplFileObject('./directory/test-file.txt', 'r', true);
    var_dump($file->getRealPath());

} catch (RuntimeException $e) {
    echo 'File does not exist';
}


Expected result:
----------------
/wwwroot/directory/testfile.txt
/wwwroot/directory/testfile.txt

Actual result:
--------------
false
/wwwroot/directory/testfile.txt

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-20 21:49 UTC] colder@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

SplFileObject will expand to the full path internally in case include_path is used.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 10:01:29 2024 UTC