Undefined Variables In PHP

Once again I find myself cleaning up undefined variables referenced in PHP. Yet more bedroom coders who think they can write stuff, causing notices, errors and warnings to spew out just simply because they can't be arsed to learn to use isset().

THIS IS WRONG:
if ( ! $_REQUEST['blah'] ) {
echo "thingy isn't set";
}

THIS IS RIGHT:
if ( ! isset($_REQUEST['blah']) ) {
echo "thingy isn't set";
}

For crying out loud, is it any fucking wonder PHP gets such a bad rap when you bloody idiots are making vague assumptions about undefined values being FALSE? I should set fire to every bastard one of you.

(Next week's rant: !== vs !=).

« Prev item - Next item »
--------------------------

Comments

Now, y'see... some of us would argue that the runtime should defend against that at compile time, on general principles.

Oh, wait. PHP. Principles. Yes, I think I see the problem.

Peter Crowther • 01 April, 2009 • 12:29:22
It's another example of the difference between OS and App coders ... most of your "bedroom coders" have probably never even looked in the log files, if they know they exist. As long at they don't get an http 500 error when they run their latest webapp, they don't care ...

Me, I do everything, and look in the log files first.. hate them getting full of error messages. And who made browsers look for bloody favicons on seemingly every access.....?!?!!

As for next week, you might touch on the difference between = and == within an IF too .... that particular typo bit me recently.. took ages to find.

Rob • 01 April, 2009 • 14:51:30
Can't you put an @ sign before it to turn off the warnings or something? That sounds better. Can I get a job now?

John Leach • 01 April, 2009 • 19:03:55
you promised a subsequent rant and did not deliver.

this is not like you.

Erica • 13 April, 2009 • 17:37:47

Leave comment

:

:
:



Categories

Me, Myself, I

Archives

Search


Calendar

< September 2010 >
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
27282930   

Get In Touch

If you want to send me a message privately, please use this contact form.

Other Blogs

www.flickr.com
c4pnb's items Go to c4pnb's photostream

Disclaimer

All opinions are those of my own, and not necessarily those of my various employers. Even if I am a Director of the company. Seriously.