To NULL or Not to NULL

I’ve found programmers that I’ve worked with lately don’t like my use of null declarations in PHP. I come from a Perl and JavaScript background (with just enough C++ to be dangerous but not particularly useful), so I tend to declare variables before assigning them values (granted, it’s not a requirement in Perl, just a good idea).

If it adds to the complexity (and/or size) of code, why do it?

Yes, it will make the file a little bit larger…but I’ve never seen—or heard of—a minimized PHP file. Minimizing is great for client-side code (primarily JavaScript, HTML, and CSS) but unnecessary when servers handle the workload. You can find discussions of single- vs. double-quotes all over the Internet, even on PHP.net, but declaring variables in PHP seems odd because there’s no requirement to do so (technically, a variable in PHP has a NULL value when declared…but that doesn’t mean you won’t flag a notice).

Why do I [usually] declare NULL?

  1. Clarifying code; by declaring everything before I use it, I know what variables to look for later when I’m debugging (OOP PHP does this out of necessity with class-level variables)
  2. When using an IDE, the software auto-references those variables later; if I don’t have a matching variable, it won’t reflect in the IDE and I can catch typos before they become time-sucking issues
  3. Finally, PHP flags a notice-level error when a variable is referenced that has not been pre-declared; not everyone knows to turn off notice-level errors, and it’s a waste of log space (and effort to dig through logs full of notices)

I highly recommend working with other programmers; I believe it makes us better coders, we learn new ways of doing things and thinking about things. For continuity, you need to agree on programming conventions. I’m not overjoyed about giving up NULL declarations, but all things change—Facebook just released their fork of PHP, Hack.

Lime Light CRM API

I put up a new repository at GitHub yesterday that converts the entire Lime Light CRM API into a simple PHP class. The superclass (creatively called LimeLight) has two child classes, Membership and Transaction (with respect to the pertinent Lime Light APIs). This is a work-in-progress and is still in beta…it’s mostly bug-free. As there is no official PHP implementation (only recommendations and companies that will integrate for you), I figured it was high-time for an open source version. I’ve written this code probably a dozen times and frankly I’m tired of rewriting it.

Also, I lack the time to integrate Lime Light outside my existing client scope, and this is as good a way as any to put it in everyone’s hands.

It’s pretty rough and I’m working on building in controls to provide better options and more accurately reflect the API. In the meantime, take a look at the source code here, and feel free to fork it/improve it/etc. I’ve learned and benefited a great deal from open source solutions and am looking forward to giving back.

If you haven’t decided on a CRM solution yet…and you go with Lime Light CRM…tell them I sent you.

NOTE: Neither True Marketing Partners nor Lime Light CRM paid me to write this post or recommend their product. IF you buy Lime Light CRM and if you mention me on the contract, they’ll kick me back. If you buy it and don’t mention me or don’t put me down as your reference on the contract, I won’t get one cent. If you’re already using Lime Light and want to expand from the web forms to the API, this is a good place to start. I have to have a live version within a week anyway… 😉