Brian works for a web development shop with an all-too-common formula: lots of intern labor and a very high turnover. As a recent hire, a large part of Brian's job is maintaining old sites developed by various former employees.

"I was recently asked to investigate a bug," Brian wrote, "where selecting a few publications from a multi-list caused strange errors and didn't store them correctly. When I initially went to check on the error, I noticed absurdly high "values" assigned to the problematic publications..."

mysql> SELECT * FROM publication WHERE id=57;
+----+----------------------+-------------------+--------+
| id | name                 | value             | parent |
+----+----------------------+-------------------+--------+
| 57 | The Washington Times | 72057594038400000 |      0 |
+----+----------------------+-------------------+--------+
1 row in set (0.00 sec)

Brian added, "I decided to investigate further and had a feeling of dread come over me when I investigated the first few rows."

mysql> SELECT * FROM publication LIMIT 10;
+----+---------------------------+-------+--------+
| id | name                      | value | parent |
+----+---------------------------+-------+--------+
|  1 | The New York Times        |     1 |      0 |
|  2 | The Wall Street Journal   |     2 |      0 |
|  3 | Chicago Tribune           |     4 |      0 |
|  4 | Los Angeles Times         |     8 |      0 |
|  5 | The Seattle Times         |    16 |      0 |
|  6 | Austin American-Statesman |    32 |      0 |
|  7 | USA Today                 |    64 |      0 |
|  8 | Washington Post           |   128 |      0 |
|  9 | The Boston Globe          |   256 |      0 |
| 10 | The Detroit Free Press    |   512 |      0 |
+----+---------------------------+-------+--------+
10 rows in set (0.00 sec)

"When I looked at the actual PHP code, my fears were confirmed."

if(($story->regions & $region->value) == $region->value) {
        $temp_string .= $story->toString();
}

An aspiring coder had decided to sum integers and use bitwise operations instead of a separate table to store associations. Before that day, Brian had never realized PHP had bitwise operations. The is some good news, however. "To reassure anyone scared of running into the original coder," Brian said, "he left Computer Science for an English major."


Please let me know what you think of WTF: don't forget to fill out the WTF Reader Survey!
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!