Implement file_get_contents() method for SplFileObject
| Request #65545 | Implement file_get_contents() method for SplFileObject | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2013-08-25 01:31 UTC | Modified: | 2014-03-07 11:07 UTC |
|
||||||||||
| From: | sherifsabry20000 at gmail dot com | Assigned: | datibbaw (profile) | |||||||||||
| Status: | Closed | Package: | SPL related | |||||||||||
| PHP Version: | Irrelevant | OS: | ||||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2013-08-25 01:31 UTC] sherifsabry20000 at gmail dot com
Description:
------------
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" );
$text='';
foreach( $file as $line ) {
$text.=$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
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2014-02-12 06:14 UTC] datibbaw@php.net
I've added a PR to add fread() as one of the methods you can use, so: $text = $file->fread($file->getSize());