php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54570 SPLFileObject returns the content of a file after it was deleted
Submitted: 2011-04-19 22:46 UTC Modified: 2011-04-29 09:55 UTC
From: bugs dot php at mohiva dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.3.6 OS: Gentoo Linux
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: bugs dot php at mohiva dot com
New email:
PHP Version: OS:

 

 [2011-04-19 22:46 UTC] bugs dot php at mohiva dot com
Description:
------------
With SPLFileObject it is possible to return the content of a file, after the file was deleted.

Test script:
---------------
file_put_contents('/tmp/file.txt', 'test');
$file = new SplFileObject('/tmp/file.txt');
unlink('/tmp/file.txt');
var_dump(file_exists('/tmp/file.txt'));
while (!$file->eof()) {
    echo $file->fgets();
}

Expected result:
----------------
bool(false)

Actual result:
--------------
bool(false)
test

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-29 00:17 UTC] tyra3l at gmail dot com
http://stackoverflow.com/questions/196897/locking-executing-files-windows-does-
linux-doesnt-why/196908#196908

Tyrael
 [2011-04-29 00:20 UTC] tyra3l at gmail dot com
shorter url:
http://bit.ly/kdhzpQ 
it is normal that you can access a deleted file if you have an open file 
descriptor for that file.
and this is exactly what happens here

Tyrael
 [2011-04-29 09:55 UTC] bjori@php.net
-Status: Open +Status: Bogus
 [2011-04-29 09:55 UTC] bjori@php.net
Expected behavior.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 09:01:34 2025 UTC