"One morning," wrote Justin Reese, "my client reported that was a strange bug on a certain page in an app I built for them. Where the contact information for a series of offices was being displayed, all the information was correct except for one piece: the phone number. For multiple locations, the phone number displayed was the same: 214-748-3647."

"I ran a quick query against the database to make sure that the phone number records were indeed correct, and in fact they were. Many of the phone numbers were 214-numbers (being that we're in Dallas and all), but there were only a handful of expected duplicates. Not nearly as many as were being displayed. More peculiarly, on my local machine, the phone numbers were displaying just fine. I tried them out on the test site, only to find they were working there as well.

"There was only one thing that could explain this discrepancy, and that was that someone mucked with the production code, perhaps doing a database misjoin somewhere or another. Perhaps it was the overzealous web designer, who had been itching to 'try some PHP instead of HTML'? Or maybe it was the boss, who once-upon-a-time was a programmer himself? The client swore up and down that no one touched the code, but I downloaded the source code anyway.

"And when I ran a quick diff on the files: yahtzee! The code files were totally differe—oh wait, no, I was just comparing the wrong set of files. Nope, the files were identical…. which meant that it was something else. It took a little while, but after much trying and testing and squinting, I finally got a clue.

  1. My PHP Class gets the data via an XML API
  2. It serializes the XML into SimpleXML objects
  3. In certain parts of the site, I turn those SimpleXML objects into even-simpler PHP arrays
  4. As part of that process, I run XML attributes through a very basic type-guesser I wrote
  5. That type-guesser says "if you're numeric and not float-like, you must be an int, so… I HEREBY DUB THEE SIR (int) $value
  6. Womp womp womp

"Figure it out yet? As it turns out, 2,147,483,647 is the highest integer value addressable on 32-bit systems. The production machine's IIS instance was switched to run in 32-mode, which exactly 32-bits short of the 64-bit test machine and my 64-bit local workstation. So, when passed a phone number like 9895551212, the 32-bit PHP was looking at it skeptically and saying, well pardner, that don't look like no number I've ever seen, here's the biggest one I got, and passing back 2147483647.

"I've since learned that most things called 'numbers' are not numbers at all, and that not all 10-digit 'numbers' starting with 214 are Dallas-area phone numbers.