I’ve just begun dabbling in learning how to write PHP code for some projects I’ve undertaken over at Earn1kaDay.com. I’ve been programming in one programming language or another for the past 20 years or so. My most recent experience has been writing Windows client programs in Visual C++. I’ve also done some server-side programming in ASP, JSP, and Perl. So making the transition to PHP hasn’t been too much of a programming culture shock.
At least at first blush.
After all, the syntax is remarkably (and I should also say deceptively) similar to the C and C++ programming languages. I’m also somewhat, though not completely, used to the distinctions of interpreted scripts that are parsed on a server rather than on the client from having programmed in ASP and JSP.
What I’ve had a difficult time coming to grips with is the loose data typing in PHP. And I mean extremely loose! C++ is considered moderately strict when it comes to data typing, but PHP is downright promiscuous.
Whether a variable is a string or integer, float, or Boolean, who cares. Just trust PHP to figure out what you intended. Actually, in a lot of instances, this is fine by me, but sometimes if you’re not careful, it can bite you in the rear.
The other thing about PHP, that’s more problematic, is function behavior and support across different versions of PHP.
Unless you control the server and the build of PHP, you are pretty much forced to code for the lowest common denominator of PHP versions. At this point in time, it doesn’t seem like most Web hosts have migrated to PHP 5. So using features that are only supported in PHP 5 will not make your scripts compatible with most of the Web hosts out there.
From a syntactical standpoint, there are 2 peculiarities of PHP that constantly trip me up and this is probably since my primary programming background is in C/C++.
The bloody ‘$’ symbol that must be prepended to all variables is the hardest for me to get used to. I’ve left it off so many times that it’s now the first thing I check for when debugging scripts that produce errors. I realize that this is a necessary evil in order for the PHP parser to be able to distinguish variables from statements. This all goes back to the loose data typing in PHP since there is no data type required when declaring variables, but it still drives me up a wall when coding in PHP.
The other thing that consistently trips me up is the requirement to use the “global” construct when declaring global variable for use within a function. In C/C++ you can just reference global variables directly. So again, if I see empty values when attempting to print out global variables, I know immediately what I’ve overlooked.
One final thing that takes some getting used to when programming in PHP is the inability to use a debugger to debug PHP scripts. Of course this is the same deal with any server-side scripting language whether it’s ASP, JSP, Perl, or others. I guess I’ve been spoiled with Visual Studio for C++ and even Eclipse when programming in Java. The only recourse for debugging PHP scripts is to use the trusty “echo” or “print” functions.
Boy, that takes me back to the early days of programming in C during the good old days of DOS!
Despite these few idiosyncrocies, I’m really growing to like writing code in PHP. The potential for server-side, hosted applications seems unlimited. These sort of apps are not limited by operating systems such of Windows, Linux, or Mac OSX on client computers. Just surveying the landscape of truly brilliant PHP scripts that seem to come on the market every month for the IM community gets the light bulb in my brain glowing brightly.
PHP will be the train that takes IM into the future.
Tag: Programming












0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment