I've recently been working through the PHP|Architect's Guide to PHP Design Patterns and have decided to build my own version of an active record along the lines of the one in Ruby on Rails. It's turning into an interesting experience as I'm doing using Test Driven Development methodology. This is proving very useful as I don't really have a clue where I'm going with the design, and so having a series of tests for each… continue reading.
Everyone else is talking about the PHP Collaboration Project, so I thought I would too! I think this should be fun. There are two strands from what I can tell: A framework. A Zend plugin for Eclipse I currently use Zend's Studio and think it's great. it's expensive though and, to be honest, the problems revolving around editing have long been solved. Eclipse is a nice enough IDE and I think it would be better… continue reading.
Profiling the quick and dirty way works for me a lot of the time. Other times, Zend's profiler is better, but when I just want to work out which function is taking all the time, the following function peppered throughout my code tells me what's going on:
global $perf_print_start, $perf_print_delta;
$perf_print_start = microtime_float();
$perf_print_delta = $perf_print_start;
$e = microtime_float();
$since_start = sprintf("%.04f", ($e-$perf_print_start));
$delta_time = sprintf("%.04f", ($e-$perf_print_delta));
$perf_print_delta = microtime_float();
$now = date('H:i:s');
if(PHP_SAPI == 'cli')
echo "Perf: $now: since start: $since_start,";
echo " delta: $delta_time - $msgn";
echo "<p>$now: since start: $since_start,";
echo " delta: $delta_time - $msg</p>";
Seems hard to believe that PHP is 10 years old! I know it's quirky and not "elegant" in a lot of ways, but it fits what I need to get done like a glove. I especially like how it doesn't get in the way of creating kick-ass applications for the web!
This is some code that I wrote to create dynamic tabs. I use it for forms where I have a lot of fields and a good percentage are "advanced" or otherwise not important enough to have visible immediately. The CSS is based on ideas from Silverorange Labs and the JS code is mine. The code is released under the MIT license which basically means you can do what you like with it as long as… continue reading.
Apart from my day-job, I also do a very small amount of freelance work, mainly for my old company. The weirdest thing about this work is that they don't use any version control system for their websites. So far, I've fixed one particular bug 4 times… It's got to the point where I keep their sites in my version control system so that I can find out which bits of my code they have broken… continue reading.
The most common way to debug is to stick echo statements into your code at strategic places. If you are feeling clever, you might even output a variable's value too:
echo "<p>here: $myvar = $myvar";</p>
I call this runtime variable inspection and as PHP is a script language, it's a very fast way to debug a script. You stick the echo statement at strategic points and with a few page refreshes in the browser, you have the troublesome bit… continue reading.