PHP File buffer

Ok, so it has been said that normal posts here are “techy DIY” so I’ll give that a go. Recently I have been working on a template engine, its not just varable replacement, its more for the back end and controls the way the site is built, not just the way it looks.

There are some quirks with the PHP 4 object model that make the job a little bit ugly, mainly the missing property access methods. But to parse the template file we can basicly use a cascading object tree, passing a file buffer down a tree as its built.

The reason for using the buffer is speed, its quicker to just read the whole file in to memory, and then just pop along it. Using an object means we don’t also have to pass the index with the buffer as well as being just hand for adding short functions.

Any way, as I am still working on the main parser part, or at least the latest version there of. I’ll go with the file buffer. It a fairly straight forward object.

The base class in this case doesn’t do any thing, I just use it as good style.

BaseBufferClass is used as a basic buffer, this can then be passed around as a slightly lighter buffer in the parser objects. It maintains the storage and pointer.

The file buffer class then extends the baseBufferClass to add file access. This is mainly done by the use of the constructor and openFile methods. When a file name is passed in the constructor openFile is then called to load the data from the file. If the file name is not passed, then openFile can be called directly.

Its not the worlds most complicated bit of code, but it fairly handy.




You can subscribe via e-mail to get my posts in your Inbox, or stalk me on numerous other platforms.

, ,

3 Responses to PHP File buffer

  1. PCGeek January 27, 2006 at 8:35 pm #


    10 CLS
    30 PRINT CHR$(42)
    40 GOTO 20
    50 END

  2. Haydies January 27, 2006 at 11:56 pm #

    ewwww. a goto… any one that uses a go to by choice needs to have their balls removed with a blunt spoon or simular for people with out balls.

  3. marco September 8, 2010 at 10:10 pm #

    how to use this script? Do you make direct call or do you create new instance to read a file?

Keep up with me on Social Media by following me below - Thanks so much!