|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24677 [PEAR] File::readAll() does not close file handle after reading
Submitted: 2003-07-16 09:08 UTC Modified: 2005-05-24 01:00 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: pjones at ciaweb dot net Assigned: coredumb (profile)
Status: No Feedback Package: PEAR related
PHP Version: Irrelevant OS: OpenBSD 3.1
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: pjones at ciaweb dot net
New email:
PHP Version: OS:


 [2003-07-16 09:08 UTC] pjones at ciaweb dot net
When using File::readAll() to read the entire contents 
of the same file more than once in the same script, the 
first readAll() returns the contents properly, but 
subsequent readAll() calls do not.  I think this is 
because readAll() does not close the file handle when 
the method is complete (it leaves the file handle open, 
thus locking the file off from subsequent access).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-31 04:24 UTC]
That should fix it?

Can anyone take a look at it?

Index: File.php
RCS file: /repository/pear/File/File.php,v
retrieving revision 1.24
diff -u -u -r1.24 File.php
--- File.php    28 Jan 2003 11:19:27 -0000      1.24
+++ File.php    31 Jul 2003 09:23:38 -0000
@@ -173,7 +173,7 @@
             $file .= $tmp;
+       File::close($filename);
         return $file;

@@ -352,15 +352,21 @@
     * @param  string $mode     Mode the file was opened in
     * @return mixed            PEAR Error on error, true otherwise
-    function close($filename, $mode)
+    function close($filename, $mode = FILE_MODE_READ)
-        if (!PEAR::isError($fp = &File::_getFilePointer($filename, $mode))) {
-            $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
+        $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
+        if (!isset($filePointers[$filename]) OR !is_resource($filePointers[$filename])) {
+            if (PEAR::isError($fp = &File::_getFilePointer($filename, $mode, $lock))) {
+                return $fp;
+            }
+        } else {
+            $fp = &$filePointers[$filename];
+        }
+        if(isset($filePointers[$filename][$mode])) {
-            return fclose($fp) ? true : PEAR::raiseError('Failed to close file: ' . $filename);
-        return $fp;
+        return fclose($fp) ? true : PEAR::raiseError('Failed to close file: ' . $filename);


 [2003-09-30 13:40 UTC] pmjones at ciaweb dot net
Sorry to take so long to get back to you.  Applied the 
patch, does not appear to work.  Using File::readAll() 
on a file the first time gives a notice "Undefined 
variable 'lock' at line 360 in File.php'" but reads the 
file OK.  Using it subsequently on the same file, it 
goes into an infinite loop with "WARNING [feof(): 7 is 
not a valid File-Handle resource] in file [/usr/local/
share/pear/File.php] at line [209]".
 [2004-08-02 23:01 UTC] c0254328 at hud dot ac dot uk
Anybody managed to fix this problem. I have just come accross this myself. I tried the patch too with no success.
 [2005-05-24 01:00 UTC] pear-dev at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 01:01:31 2024 UTC