Posts Tagged ‘PHP’

The magic empty string that is not empty

Wednesday, May 14th, 2008

I just helped one of our developers with a weird problem. The piece of code he was working on contained roughly this:

 
if ($str!='')
{
   echo "Hello $str";
}
 

He was importing a CSV file that didn't contain a value for $str, so $str was an empty string. So it should skip the echo statement according to the above code, right?

Wrong. The script echoed "Hello ". It completely did the $str!='' wrong.

In a debugger, we watched the value for $str and watched it step through the code. We clearly saw that while $str was empty (""), it executed the next line. Almost seems like a bug in the != operator but that obviously can't be the case.

This kind of baffled us.

To investigate, we var_dumped the value of $str, and this gave a very weird output:

 
   string(3) ""
 

An empty string, with a length of 3?

Eventually we noticed there were some weird control characters in there that translate to an empty string in output, but that do have a length. (Somehow this reminds me of black holes and dark matter).

We removed the char from the file (apparently, in a text editor, you could do 'delete' on the char, and although this didn't have a visible effect as it was an empty string in a text editor as well, it did work and we were able to process the file).

Lesson learned: not every empty string is an empty string. Control characters can have very weird effects. It can make a string look empty while it's not.

By the way: the people who created this file did so on a mac and uploaded it to a linux server. The weird chars were only at the beginning of the file, only on the first line. Does anybody know if there is some mac/linux/windows conversion that could cause these chars to appear?

PHP and Scalability

Monday, March 17th, 2008

Martin, one of our system architects, has written an article on our corporate blog about scalability in PHP.

He covers things like frontend generation (as opposed to request based caching), database replication, loosely coupled components to increase the scalability of the application, and he even mentions SOA (Service Oriented Architecture). We've recently had some good results with implementing SOA architectures in PHP. Traditionally SOA is associated mostly with Java, but with PHP5 it's very well doable.

Read his post here.

Interview in Computerworld UK

Tuesday, February 26th, 2008

I was recently interviewed by Computerworld UK regarding our launch in the UK and the current rise of PHP in the corporate world.

The result is online here.

The 'leading PHP expert' phrase are not my words, but pretty cool. :-)

How do you see PHP pickup in your country? The Nexen stats are one thing, but how businesses are using it is another. Post a comment to let me know how 'PHP' and 'Business' go together in your region.

Microsoft and Sun, the Real Story

Saturday, February 2nd, 2008

So one day, Scott McNealy, founder and chairman of Sun, read in his morning newspaper how the use of Java was rapidly diminishing, courtesy of something called 'The LAMP Stack'. Furiously, he called his accountant.

Scott: "I knew this Java thing was a bad idea in the first place! I see only one solution. We need to buy this Lamp!"
Accountant: "Euh, LAMP is not a company. It's an acronym. It's Linux , Apache, MySQL and PHP"
Scott: "Then buy me Linux!"
Accountant: "But we still have this Solaris thing.."
Scott: "Then buy me Apache!"
Accountant: "That's a foundation. Nothing to buy there."
Scott: "Then buy me MySQL!"
Accountant: "We don't do databases."
Scott: "It's a database?"
Accountant: "What rock have you been living under?"
Scott: "Sweet. I can own the Lamp AND piss off Oracle at the same time!" (waves fake plastic magic wand) "Make it so!"

And so it happened.

Ten days later, Microsoft CEO Steve Ballmer was reading the CIO Magazine, and read about this interesting thing called PHP, that according to the author you could use to write "WHAT?!". "WHAT?!", obviously a highly advanced and evolved version of "Hello World", caught his attention. So he called Bill Gates.

Steve: "Hey, you heard about this PHP thing?"
Bill: "Pee Age Pee? You're not that old yet, are you?"
Steve: "What? No, wait, it's a programming language, apparently better than ASP.NET."
Bill: "Who cares if it's better. I mean; we made the worst operating systems ever and still rule. (Checked out Leopard yet? It is SO cool.)"
Steve: "I don't know Bill... remember that internet thing that we didn't know about years ago? Kind of nearly missed the boat there."
Bill: "Right. Didn't we solve that in the same way? Worst browser, highest market share, that sort of thing?"
Steve: "Yes we did, but then we also didn't know about this 'mp3' thing until it was too late."
Bill: "We did manage to make Zune the worst player, but somehow we're not market leader. Guess we got sloppy?"
Steve: "Maybe it's just different times. Maybe we should have a different strategy."
Bill: "Ok, so let's just buy PHP then."
Steve: "It's not a company. But Encarta says it's written by a Rasmus Lerdorf."
Bill: "So let's hire him."
Steve: "Tried that. Didn't want to join. Can't blame him, works at Yahoo."
Bill: "Then I guess we'll have to buy Yahoo."

So it happened.

Two of the most controversial announcements of this month, and both appear to be part of devious plots to take over the LAMP stack. What's next? My prediction: Red-Hat buys Zend; Oracle buys Red-Hat; Sun and IBM join forces to buy Oracle, Microsoft buys Sun, kills IBM and peace is restored in the galaxy.

P.S. Can you imagine Microsoft running sites like Flickr? These guys invented MS Paint!