I have been writing in PHP for more than six months, and while I am far from an expert, I can easily get around and turn the scripts into everything I need. I come from an object-oriented background, and this is what PHP seems to use very little, if any, in its default libraries.
Most of the external libraries that I use or create work with an object-oriented design, while the following example is used by default. I will use the file reading / writing 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 it would be wiser for me to use a design that looks something like this:
$file_handle = new FileStream("/path/to/file.txt"); $content = $file_handle->read(); $file_handle->close();
Now Iām quite sure that there will be a certain argument for this, since the same idea applies to strings, arrays, cURL, MySQL queries, etc. I would be interested to know what it is.
So, if it is better to write separate functions, taking a descriptor or resource as the first parameter, for example.
object_method($handle, $value);
Then why do most popular (external) PHP libraries prefer to use:
$object->method($value);
And what should I use when writing my own libraries and applications?