I'm sorry this might be ridicules question but I have been using filesize() for my 4 months of php coding (I'm new to php) and I always think of it as the php standard library function for getting a file size. but now I was reading about Standard PHP Library (SPL) and I surprised that there is another function called SplFileInfo::getSize which do exactly the same thing
filesize()considered a standard php function or not ?
What is meant by
standard? As I see in a manual
filesize() exists since php4 (which didn't support OOP in a proper way). So, this function is a procedural way of getting a filesize. You need only path to file and what you get is a size. And nothing else.
filesize()considered a standard php function , why the php creators bother themselves by making another function
SplFileInfo::getSizedo the same thing?
In php5 (as you can see
getSize is available since php5) more object oriented features had been added to php, they all are part of Standard PHP Library or
SPL. So, in php5 you can consider a file like an object with properties - name, size etc. So for getting one property or another - there's a method. For getting filesize is
getSize is not a function, it's a method of a class
SplFileInfo::getSize()? which one should I use?
As we already learned -
filesize() uses a procedural approach:
$filename = '/path/to/file.ext'; $size = filesize($filename);
getSize() is a method of a class, object of a class should be created first:
$filename = '/path/to/file.ext'; $finfo_obj = new SplFileInfo($filename); $size = $finfo_obj->getSize();
So, it's up to you to decide what function and which approach to use.