Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any PHP OO file API?

I know that PHP includes a lot of built-in functions for handling files and directories. I can read, write, delete, and I can get almost any possible information about files thru the use of PHP filesystem functions the problem with these functions are that they are all procedural.

Is there any PHP OO file API ?

I doubt that there is a native one, at least in < 5.3. I am looking for some 3rd party extension or class to achieve this.


1 Answers

Yes, yes there is, and it is beautiful. SplFileInfo and SplFileObject (which is the one you probably really want) were both available in 5.1.2.

While they are mostly just wrappers around procedural functionality, I find them far nicer overall -- if only because they allow me to pass things around while using type-hinting, and because I don't need to worry about fclose.

I guess it's similar to the PDO classes. Yes, you can do things procedurally, but why would you?

like image 134
cwallenpoole Avatar answered Jan 23 '26 14:01

cwallenpoole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!