开发者

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开发者_StackOverflow社区 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.


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?


In 5.3 you can use SPLFileObject.


Oh god no, procedural, the horrors! But in fact there are SplFileObject and SplFileInfo and SplTempFileObject, albeit they only map the base functions partially.

There is no comparable directory API, but e.g. RecursiveDirectoryIterator can be used for reading. For a traversal API look into Hordes/PEARs VFS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜