Note to anyone else who might do the dumb thing I did. When you're handling GET/POST input in PHP and wan to know if a value is numeric, don't use is_int() because it'll lie to you. What you want is is_numeric(). Of course, the is_int() documentation specifically warns you about this, but it doesn't do much good if you read right past it.

I was *this* close to walking over to Rasmus or Andrei and asking for a sanity check, but I decided to re-read the docs one more time. Heh. There's an hour or so I'll never get back.

Of course, this *is* the first PHP work I've done in quite a while. You don't want to know how many times I tried to declare a variable like: my $foo, thinking it was Perl. I think that's finally out of my system.

Note: Coments may be off-line for a bit. I'm being DoS'd by some comment script kiddies right now. Retards.

Posted by jzawodn at January 29, 2004 11:50 AM

Reader Comments
# Vegard said:

Or maybe it's yet another version of MyDoom?!? :)

on January 29, 2004 01:50 PM
# Larry said:

Yep, no kidding. But what do you expect from a mysql'er? That database has laughable data coercion.

on January 29, 2004 02:00 PM
# Donny said:

I agree with you on the my $foo, when I first started using PHP instead of Perl which was a while ago now, I would do that all of the time!

Donny

on January 29, 2004 02:10 PM
# Doug said:

Thanks Larry, for your valuable input. Oh wait, no, that was completely worthless and is nothing but flamebait considering what you said is not only off topic but also makes little sense. Good try though.

on January 29, 2004 02:12 PM
# Sven said:

LOL, can you imagine being able to just WALK over to Rasmus or Andrei for PHP help? Me thinks they'd probably just tell you to RTFM!! ;P

on January 29, 2004 02:19 PM
# Jon said:

Hell, if ONLY I could just walk over to either one of them for help! :)

on January 29, 2004 02:57 PM
# Jeff Boulter said:

A similar one that has burned me is defined() vs. isset(). defined() is for something goofy like contansts and isset() is what you really want to check if a variable is defined. Gah!

on January 29, 2004 08:43 PM
# philip said:

I sometimes use my declaration in javascript too. Doesn't help that I often have the same validation algos in js as well as perl, and if you've been at it for a few hours, the syntax hilighting in vim makes it look very similar.

on January 29, 2004 10:15 PM
# Dirk said:

Believe it or not, I had the exact same problem a week ago which brought me to the function description, where it was clearly stated :)

And I think we share the same background. I learnt Perl first, and when I started PHP I was always thinking "man why can't I just do it as in Perl?".

on January 30, 2004 12:39 AM
# Ted R. said:

The one thing that has kept me with php so consistently over the last 2 years is that /everything/ is addressed in the online docs. If it's not in the official function description or feature descriptions, the well-moderated boards ensure that each and every OS/db/phpversion anomelie is addressed. Working alone w/o even another engineer (nonetheless Rasmus) I have found the php docs to make up for that 10 fold.

Thank you php community, 10x!

on February 3, 2004 01:03 PM
# Shot said:

That’s why, in such cases, I always try to first cast the user data to the int type, and then check whether it isn’t a zero. It’s not the same thing, of course, and not every time things can be simplified this way, but when they can I feel somehow safer knowing I *do* have a real integer (no pun intended) now.

on February 4, 2004 12:22 PM
# Sterling Hughes said:

Funny thing about that - andrei was actually the one that added the is_numeric() function. :)

on February 4, 2004 03:04 PM
# tiffany said:

There's also the ctype_digit() function that checks whether or not a string contains all numeric characters. For example:

$n = '1234.5';
var_dump(is_numeric($n)); // returns bool(true)
var_dump(ctype_digit($n)); // returns bool(false)

on July 31, 2006 01:53 PM
Disclaimer: The opinions expressed here are mine and mine alone. My current, past, or previous employers are not responsible for what I write here, the comments left by others, or the photos I may share. If you have questions, please contact me. Also, I am not a journalist or reporter. Don't "pitch" me.

 

Privacy: I do not share or publish the email addresses or IP addresses of anyone posting a comment here without consent. However, I do reserve the right to remove comments that are spammy, off-topic, or otherwise unsuitable based on my comment policy. In a few cases, I may leave spammy comments but remove any URLs they contain.