After some research, discussion and a bit of hacking together some poorly organized code, I’ve come up with a revised interface from my previous post An experiment: Django Framework-like querying/model interface in PHP.
Now there existed a few problems I was well aware that I wanted to address if I was going to spend any more time on a good, clean interface that promoted rapid development and readable code:
- It was dependent on a PECL extension that was nearly 4 years old
- It only worked with PHP 5.2.x (as per above)
- The actual query-building interface wasn’t pretty and hindered readability
I sat down and revised a good portion of the old code I had put together and came up with something that fixes these problems. I wrote a new collection of classes with PHP 5.3 in mind and it uses a lot of the new language features (especially late static bindings and the __callStatic magic method). Now, because of the use of these new features my code is now dependent on PHP version 5.3 (developed using 5.3.1) — but, I suppose it’s better to code looking to the future rather than being locked into an older version. View full article »
I have continued with this experiment and created a new querying interface compatible with PHP 5.3 and has no dependent PECL extensions: Experiment update: revised Django-like PHP (5.3 compatible) querying interface.
So this is an experiment I’ve had in the making for quite some time. I’ve been working for years trying to build a reusable “generic object” querying framework that I made my PHP applications easier to maintain and faster to develop. I originally started with a small library of classes, including a ‘GenericObject’ class and a ‘Collection’, which allowed for proper iteration using the Iterator interface — all wrapped around a very messy Factory design pattern.
Up until about a year, I used hacked and modified versions of these classes for all of my projects and was getting tired of the mess. After doing some casual research I finally came across the Django Framework and found the object creation and database querying quite phenomenal as a programming interface. I didn’t want to spend years trying to get my Python up to par with my abilities with PHP, so I decided to try and replicate it. For the last year, again, I’ve been using a pretty hacked up version of what seemed to me like a “Django-like” interface, combined together with my old GenericObject and Collection classes from long before. With this, I was previously able to perform really simple database queries with an interface like so:
$users = User::get(array("fullname__contains" => "Andrew"));
foreach($users as $user) {
// ...
}
View full article »

Map of Canada chart with province value colour coding.
This is PHP class I developed for work when I needed a Canada-specific map chart in some reporting tools I was creating. Obviously Google’s Map Charts API would’ve been my first choice, but it didn’t support Canada as it’s zoom level for reporting province-based data sets.
This is where I sat down, thought about a quick and dirty way to create this chart and went to work. I was able to create a chart as show on the right, with full control of output dimensions and colours.
Before I jump right into the full code, I want give a brief explanation of some of the techniques I used to accomplish this task.
View full article »
So here’s a quick couple snippets of code that will allow you to retrieve the coordinates of two locations using Google Maps API — no API key necessary.
This first function will return the coordinates of specific address (I find pretty much anything works, whether it’s a full address with street number, or just a postal code, or simply a city name) as an array of coordinates:
function getCoordinates
($address) {
$url = "http://maps.google.com/maps/geo?q=" . urlencode($address)
. "&output=json";
$result = file_get_contents($url);
$result = json_decode($result, 1
);
if (isset($result['Placemark'])) {
list($lat, $long) = $result['Placemark'][0]['Point']['coordinates'];
} else {
$lat = $long = false;
}
return array($lat, $long);
}
View full article »
I don’t quite know what gave me the desire to ever generate audio (specifically MP3) waveforms with PHP — it’s not something I’ll likely ever use — but after doing some research and coming up a bit short I decided to make it happen.

Waveform generated using Dancing With Paris' "(Boardwalk)" MP3.
A few days of Googling, I did come up with a couple solutions but none seemed to really produce the results I wanted. All I was looking to generate was a simple waveform like that in Cubase or other recording software. I don’t need axis labels or left/right audio splits, just a simple mono waveform from an MP3. I also didn’t want to go through hundreds of audio files and convert them into WAV files just to do this — if I was going to do this as an experiment, I wanted it on the fly. I did come across some interesting links though:
View full article »