I have been writing in PHP for just over half a year now, and whilst I am a long way off being an expert, I can get around quite easily and turn out scripts for whatever I need. I come from an object-oriented background and this is something that PHP seems to use very little of, if at all, in its default libraries.
Most external libraries I use or create, work with an object-oriented design whereas the defaults seem to use the next example. I'll use the file/writing reading process as an example:
$file_path = "/path/to/file.txt";
$file_handle = fopen($file_path, "w+");
$content = fread($file_handle, filesize($file_path));
fclose($file_handle);
Now to me, it would make more sense to be using a design that looks something like this:
$file_handle = new FileStream("/path/to/file.txt");
$content = $file_handle->read();
$file_handle->close();
Now I am quite sure that there will be a definite reasoning behind this, as the same idea is applied to strings, arrays, cURLs, MySQL queries etc. I would be interested to know what it is.
So, if it is better to write distinct functions taking a handle or resource as a first parameter e.g.
object_method($handle, $value);
Then why do most popular (external) PHP libraries prefer to use:
$object->method($value);
And which should I be using when writing my own libraries and applications?