From The Annals Of Trivial Programming Errors

It was pointed out to me that the alphabetical list of groups on my web site was very short.  It seemed to only list a tenth of the groups I probably had albums from.

Here’s the snippet that constructs an array by reading the directory that contains all the group names:

while ($group = readdir($dir))
  $groups[] = $group;

See the error?  Yeah, I had bought an album from the group 0, and that made that loop terminate when it reached that group name.  (readdir reads in unsorted directory order, so it didn’t terminate immediately, which is why I hadn’t noticed.)

0: The Bobby Tables of bands.

The fix is something like

 while (($group = readdir($dir)) !== false)
   $groups[] = $group;

PHP type coercion is usually convenient, but…

One thought on “From The Annals Of Trivial Programming Errors”

Leave a Reply to AdamCancel reply