PHP Tip: Always Put Constants on the Left in Boolean Comparisons

This was a standard I enforced at my last company: Whenever you are doing a boolean check (such as an IF or WHILE), always place constants on the left side of the comparison. The following is BAD: // BAD if($user == LOGGED_IN) { The following is good: // GOOD if(LOGGED_IN == $user) { Why is […]

BUG: Constructors, Interfaces, and Abstracts Don’t Mix Well

I just discovered a bug today in PHP 5.1 (haven’t confirmed if it was fixed in newer versions). When trying to enforce interface arguments on constructors, PHP behaves unexpectedly. Normally, interfaces allow you to enforce argument counts or types in child class methods, but not with the constructor (and probably destructor). Crash course on interfaces: […]

A Great Web Developer is a Great Application Developer

After being a part of the developer hiring process for a while now, I have begun to see what distinguishes an exceptional web developer (the ones that get hired faster than we can even make an offer) and everybody else. Things have changed since 1995 – web development requires actual knowledge of programming! The problem […]

Permission Denied in the PHP Destructor and the Current Folder

I learned something new today, so I’m going to share two cool things with you. File access is screwed up during a destructor call in PHP. I will show you how to get around this. How to create a universal absolute path variable that refers to the current folder you are in. For the application […]

Boolean and 0.00

ARG. I encountered another potential issue in PHP that is due to loose types that is common if you are using a database back end. $amount = 0.00; if($amount) Versus $amount = ‘0.00’; // how data from databases comes if($amount) Guess what happens. Well, most people might say both should be TRUE, but that’s not […]

Clean Coding

Consider the following source code: $uSess = uLogin($uName, $pwd); That’s a fictional piece of code that might exist in a login script. The uLogin function, short for “user login” versus, perhaps, aLogin for “admin login”, accepts two parameters: a username and a password and assigns the result to a session variable called “uSess”. This sort of […]