PHP is_numeric() vs is_int()

Written by Donncha on March 31, 2009 – 9:46 am -

Some lessons you don’t forget, but this one I did because it doesn’t come up very often.

Don’t use is_int() because, as Jeremy says, it’ll lie to you. Use is_numeric() instead.

Copy the following chunk of code into a php file and run it. You’ll be surprised at the outcome:

$t = "12345";
if( is_int($t ) ) {
    echo $t . " is an int!";
} else {
    echo $t . " is not an int!";
}

The problem is that is_int() thinks a string of numbers is a string, not an integer. The is_int() man page has an example illustrating that but it’s easy to miss. That function should carry a public health warning!

Related Posts

  • No related posts

Subscribe to my RSS feed

WordPress Party Pictures

Written by Matt on March 31, 2009 – 2:00 am -

A
Subscribe to my RSS feed

Thursday Next

Written by Ryan on March 30, 2009 – 2:26 pm -

I just noticed that Something Rotten is finally available for the Kindle.  This completes the Thursday Next series for Kindle readers.  If you haven’t read this amazing series, start with The Eyre Affair and enjoy.

Subscribe to my RSS feed

WordPress Party Tonight

Written by Matt on March 30, 2009 – 12:55 pm -

Tonight (Monday March 30) at 7 PM we’re opening up the new Automattic space at Pier 38 for the first time because so many of our friends will be in town for Web 2.0 Expo and all their fun events. Come by our spot (on Embarcadero in between Brannan and Townsend) starting at 7 PM and enjoy good music, free booze, and geeky friends. We’re on the left corner and there’s a bunch of circles in the window and an Automattic sign over the door. (Sorry for the late announcement, if you could help us get the word out I’d appreciate it.) You can RSVP on Facebook here.

Subscribe to my RSS feed

Kylie Minogue does Monkey Man

Written by Donncha on March 29, 2009 – 3:20 pm -

Well, this was a nice start to the day. Yesterday morning I heard a catchy tune coming from the living room so I popped my head in to see Kylie singing with “The Wiggles” on NickJr. They covered Monkey Man by The Specials and I have to take my hat off to Miss Minogue. Wow.

The song is full of energy, it’s happy, it’s got that “get up and go” feel. My foot was tapping as I listened. Who knew Kylie Minogue could do Ska? Dare I say it, but she does a better job of it than The Specials?

Related Posts

Subscribe to my RSS feed

On Order

Written by Ryan on March 27, 2009 – 1:28 pm -

Some stuff I have on the way.

Subscribe to my RSS feed

WordCamp China, Hong Kong, and Japan

Written by heather on March 26, 2009 – 8:43 am -

I’ll be attending our two WordCamps in China: WordCamp China in Shanghai, on April 4, and WordCamp Hong Kong on April 5. I think this says I’m going to be in Japan for WordCamp on April 12th.

Subscribe to my RSS feed

The naked Brian Cowen

Written by Donncha on March 25, 2009 – 5:05 am -

Earlier this month someone walked into the National Gallery in Dublin, Ireland and hung a nude painting of our illustrious leader, Brian Cowen, in the “National Portrait Collection” section of the gallery.
Another painting was hung in a nearby gallery. More details can be found on this Tribune article.

Brian Cowen

Brian Cowen

All a bit of fun right? Sure, nobody wants to see a satirical nude photo of themselves hung up in public but the pictures were only on display for a short time. One or two newspapers reported on it and the national broadcaster, RTE, carried the following report on Monday night:

I never saw the original news clip. I was barely aware it had happened until this morning when the blogs and twitter were all alight with talk of the apology RTE broadcast last night. They also removed the news clip and article from their site.

RTE has to apologise and be censored for reporting the news? What sort of country are we living in? If Fianna Fail had let things lie all this would have blown over and be forgotten by now.

Ray D’Arcy speaking on TodayFM (a private national radio station) revealed the painter is Conor Cassidy yesterday, but he wasn’t the one who hung the paintings. After the show yesterday a Garda called to the TodayFM offices looking for the email of the artist to caution him. The request was refused. Ray admitted that if the Garda hadn’t called he wouldn’t be talking about the paintings today.

More coverage by Irish bloggers:

Grandad has a different viewpoint. Brave of you )

Control of the media is essential at this time, lest they say something negative about His Holiness. In fact, the Director General of RTE should immediately be reassigned to a menial task in the Ringsend Sewage Station as a lesson to the rest of those who would speak ill of our Great Government.

We must all revere and adore His Godliness for his inspired leadership in this time of crisis. Nothing negative must pass our lips.

The North Koreans have the right idea.
cowanposter

(Great caricature by Alan Cavanagh)

So, next time you see something funny about Gordon Brown or Barack Obama be glad you don’t live in Ireland. Spread the news. Check out #picturegate on Twitter.

Related Posts

Subscribe to my RSS feed

Downloadable Web Fonts

Written by Matt on March 23, 2009 – 12:38 am -

Downloadable font formats for the Web. See also: Web Font Optimizer (visit in anything except Firefox). 2009 will be an exciting year for typography on the web, particularly when Firefox 3.5 comes out this summer. Hat tip: Mark Wubben.

Subscribe to my RSS feed

rabbits in the sun [Flickr]

Written by michel v — intraordinaire.com on March 22, 2009 – 7:07 am -

michel v — intraordinaire.com posted a photo:

rabbits in the sun

Senlis, mars 2009.

Subscribe to my RSS feed