Hand Coding

There are times where I can just end up feeling like a complete numpty. This has been one of those days.

Because I’m also an epically sad git, when it comes to writing webpages and PHP (PHP in particular, in this case) I tend to write them by hand, rather than using programs like DreamWeaver or whatever to do the work for me. There’s a lot of reasons for this, primarily that if I write it I know what I’ve done, it’s fixed in my head, and I can go back later, look at it, and know what I’m doing. Dreamweaver in particular is not good for that kind of thing.

The down-side of hand-coding, though, is that on occasion you can make a right arse of things, and then it can take a while to figure it out. And that’s what’s happened today. I’ve been trying to figure out why something was displaying when it shouldn’t be. And could I? Could I eckerslike.

I’ve finally figured it out though, and it’s a simple mistake because of writing stuff by hand.

In PHP, setting a variable is done by using $variable=1;

If you then want to check the value of it, you need to use if ($variable==1) .

Yes, I was checking it with if ($variable=1), which in PHP is something that’s always true – because you’ve assigned it to be 1 in that self-same line. One character wrong, and now it’s all fixed and working perfectly. And it only took three hours to figure out…


2 Comments on “Hand Coding”

  1. bsag says:

    Hehe, I’ve done exactly the same thing in Ruby many times. Cue lots of bashing of forehead on surface of desk. 😉

  2. Pete says:

    The same problem occurs in bajillions of languages, including but not limited to C, C++ and Java. The best way of dealing with it is to adopt a convention of writing your tests as if (1 == $variable). If you accidentally write if (1 = $variable), you should get a hefty compiler error.


Leave a Reply

Your email address will not be published. Required fields are marked *