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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Apr 29 21:01:26 2025 UTC