PHP is_numeric() vs is_int()

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!

There’s also the ctype_digit() function too but it has it’s own gotcha:

Note: This function require a string to be useful, so for example passing in an integer will always return FALSE. However, also note that HTML Forms will result in numeric strings and not integers. See also the types section of the manual.

Kylie Minogue does Monkey Man

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?

The naked Brian Cowen

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 Casbey 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.

(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.

PS. Many many more blogs are covering picturegate now but take a look at this thread on Creative Ireland. Great photoshopping going on there! (Alastair)


Crash Different

An oldie, but as they say, “a goody”. For all the Mac fans who are sick and tired of their computers crashing. (Hey Mark!)
Found this on a CD while sorting through my CDRs and music collection. Most are now ripped to MP3 and the physical media is heading into the attic for safe storage.

Why is it that most of my compilation CDs are from about 10 years ago? Does music become less relevant the older you get? I’ve never bought music online but if I do, Blue Lights on the Runway by Bell X1 will probably be the first album I buy. Love “The Great Defector”, their current single.

The Simpsons come to Ireland

St. Patrick's Day So, a new Irish themed Simpsons will air tomorrow night to celebrate St Patrick’s Day and the whole world is going gaga over it.

We had lunch in Blarney today and heard from more than one person that the Simpsons will be making an appearance tomorrow at Blarney Castle! I think people are confusing reality with a cartoon storyline. Things are getting out of hand. Next thing you know, Bugs Bunny and Daffy Ducks will be spotted walking out of the Woollen Mills and drinking pints with the locals.

I have the episode set to record on Sky+ anyway. Should be a laugh.

Oh, and it’s not “Patty’s Day”. A pat is something a cow leaves behind in a field and contributes to global warming and is quite smelly. Dung beetles like it too. If you must shorten “St. Patrick’s Day”, it’s “Paddy’s Day”! Thanks Gavin for alerting me to this atrocious misspelling.

HOWTO: Make WordPress plugins work with WP Super Cache

Daffodil, snow and water droplets Thaya Kareeson has written an excellent article for plugin developers. It goes through how to make plugins work with WP Super Cache by using dynamic AJAX calls.

WP Super Cache can make static html copies of pages served by WordPress which is great for performance. Unfortunately that means some plugins don’t work because they rely on executing PHP on each request. The plugins need to be rewritten to use AJAX calls by the visitor’s browser. There’s a FAQ in the readme.txt all about it!

I previously wrote about adding AJAX to WordPress plugins but Thaya has worked through a simple example that will work perfectly with WP Super Cache. It’s a good foundation for plugin developers start from.

He also has versions of WP Postviews and Popularity Contest that have been rewritten to support static caching. I haven’t tried either plugin so leave a comment on his blog if you need help!

If you depend on a large portion of your content being dynamic this isn’t the solution for you as it will affect what search engines see. Those bots don’t speak Javascript, but for interactive purposes (ratings, stats etc) it’s the job.

reading glasses Further reading:

  • AJAX in Plugins is a must-read starting point for developers.
  • wp_enqueue_script() is the command WordPress uses to load Javascript files. That page links to a couple of good pages too including this best practices post. As of this writing, Thaya’s example don’t use wp_enqueue_script() but it’s simple to use.

The vast majority of plugins work just fine with WP Super Cache, but some of the ones that don’t are quite popular. If your favourite plugin doesn’t work, why don’t you help the author out and fix it? You have all the source code after all and you’ll be helping everyone else who uses the plugin!