Page 1 of 1

Read , Write file

Posted: Sun Jun 18, 2006 1:44 am
by quocbao
When open/read/write a file , we often use

Code: Select all

$fp = fopen($file , "rb");
$data = fread($fp,filesize($fp));
fclose($fp);
but i prefer

Code: Select all

$reader = new IO_FileReader($file);
$data = $reader->ReadToEnd();
$reader->close();
What do you think ?

Posted: Sun Jun 18, 2006 1:47 am
by TheMoose
The second method is better if you're worried about making user-friendly error handling and custom error handlers. The first method is better in terms of less code to manage, and is probably going to run faster because it's part of a precompiled built-in library.

Posted: Sun Jun 18, 2006 2:01 am
by quocbao
Of course , the second method is better :D , we can also use exception handling instead of php's old-style error report .

This is similiar to StreamReader and StreamWriter in .NET :D