|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65545 Implement file_get_contents() method for SplFileObject
Submitted: 2013-08-25 01:31 UTC Modified: 2014-03-07 11:07 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sherifsabry20000 at gmail dot com Assigned: datibbaw (profile)
Status: Closed Package: SPL related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
27 + 31 = ?
Subscribe to this entry?

 [2013-08-25 01:31 UTC] sherifsabry20000 at gmail dot com
It'd be nice to have native support for reading whole files in SplFileObject. At 
the moment one would have to read a file line by line to get the whole text.

So instead of:

    $file = new SplFileObject( "one.php" );
    foreach( $file as $line ) {
    //$text now has the contents of the file

We could do this:

    $file = new SplFileObject( "one.php" );
    $text= $file->getContents();
    //$text now has the contents of the file


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-12 06:14 UTC]
I've added a PR to add fread() as one of the methods you can use, so:

    $text = $file->fread($file->getSize());
 [2014-03-07 10:44 UTC]
-Assigned To: +Assigned To: datibbaw
 [2014-03-07 11:07 UTC]
-Status: Assigned +Status: Closed
 [2014-03-07 11:07 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 08:01:28 2024 UTC