The character, which is not

I was busy integrating a search keyword-based advertising solution into one of our clients’ site some day last week. It seemed like a no-brainer task: communication was handled by a neatly implemented php script provided by the peer company, along with a pdf document describing all what need to be programmed with lots of examples, created for dummies.

As lazy as one can be, I tried to save a few minutes by copy-pasting five relevant code lines from this pdf manual, and only changing the necessary parts to fit into the site’s code base.

Think of something as simple as

...
require_once('peer_code.class.php');
$s = new peerCodeClass();
$s->search($keyword);
foreach ( $s->results as $result)
...

Done, great. Give it a go. Kaboom.

It just didn’t work. The error log kept saying “Call to undefined function: search()”. Darn.

I don’t count php as one of my favorite languages, partly because its lack of a decent debugger. So I needed to stick to tricks like echo-ing variable values at certain points of the code, and raising error_reporting level to maximum.

So it seemed that the class does get instantiated, and $s contains a fully equipped peerCodeClass. What’s wrong then? Why does it keep telling me that search() is undefined?

I’ve checked for every minuscule warning in the error log, and fixed the code so that even the pragmatic compiler could say nothing wrong to that. I even started renaming variables and function names to avoid any hidden name clash possibilities. Still nothing. I was about to start believing in trolls, when my eyes caught one strange character in one of the error log entries. It said “Undefined variable: s­- in …”

A suspicion slowly crept into my mind. No that can’t be just it! I quickly retyped that one line with the $s->search(); and gave it another go. Bingo! It worked this time!

Folks, copy-pasting from pdf into console may result in character-alikes that are in fact something else. In my case, I’ll never know what sort of dash was in there, but definitely not the ASCII dash, which the compiler expected.

Doing the math, by copy-pasting that small piece of code I’ve saved maybe 2 minutes, only to lose 2 hours for debugging. When writing code, copy-paste is evil, and not just the usual – uh, forgot to update the parts that differ – way!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

0 Response to “The character, which is not”


  • No Comments

Leave a Reply