When you think you know more than the code...
Date: 12/07/05
(PHP Community) Keywords: php, mysql, sql
Some may find this amusing :)
First, a little preface for those that keep up with this journal. I was running on RedHat 9.0, way outdated. And when I tried to update PHP, it was a mess. So I decided that it was time to just upgrade the entire OS. Went to Fedora 4... even worse nightmare. Then I found Ubuntu... redemption.
After getting everything setup and modified: The core, PHP, http, postfix, MySQL, SSH, FTP (yeah, thank God for Ubuntu!), everything finally returned to normal Monday morning around 3:00 AM.
The whole reason for updating was due to a bug I read about a long time ago in v 4.2.2. The bug was with the sort() function. I just remembered reading about it in my O'Reilly PHP Cookbook. Most of my sorting has always been done via MySQL. So I've never had a use for sort() until this one line of code. So I'm thinking after coding and it not working "ah, this is that bug".
So I went back to that line. After all this headache, I just immediately had to know if it worked now:
$options = ksort($this->allowable_commands());
I almost got sick to my stomach. The right answer?
$options = $this->allowable_commands();
ksort($options);
So only NOW do I go back to try to find what the bug actually was that PHP Cookbook talked about (page 98):
The sort() function doesn't preserve the key/value association between elements. Instead, entries are reindexed starting at 0 and going upward. (The one exception to this rule is a one-element array; its lone element doesn't have its index reset to 0. This is fixed as of PHP 4.2.3)
My usage wasn't even CLOSE to this bug! I thought sort() returned the re-sorted array.
That's what I get for overthinking. Go ahead, you can laugh at me. I did.
Source: http://www.livejournal.com/community/php/375336.html