RSS Feed

Peter Goodman's blog about PHP, Parsing Theory, C++, Functional Programming, Applications,

Mini App: PHP Hour Tracker

Today I didn't have much to do so I created a system to keep track of my hours. It's a very simple mini application that you'll notice looks uncannily like gmail. I decided to take a break from my normal object-oriented approach to everything and write something without any classes (with the exception of exception handling). There are almost no comments in the script, but it's self-explanatory. Go check out the My Hours Timer at The way it works is that you install it by going to index.php?install and it will attempt to create a SQLite database. I abstracted away the database to functions (without classes!), the trick is a nifty PHP4-era hack that makes singletons by means of declaring a static variable within a function. You can view the source code of My Hours or simply look at how I dealt with database calls...

// OO way with iterators:
$result = $db->query("SELECT ...");
    $row = $result->current();

// non-OO way
$result = query("SELECT ...");
    $row = currentResult($result)

I could see this non-OO way being extremely useful where the nextResult and currentResult functions are generic interfaces to different object and data types such as arrays, directory listings, etc. Right now, they remain somewhat ambiguous functions in my mini app by just catering to database results.


There are no comments, but you look like you have something on your mind.