Dreaming of GOTO in PHP

Well, not actually dreaming. I was listening to Satie’s Gymnopédies and courting sleep when some PHP code started scrolling through the imaginary terminal window emblazoned on my mind’s eyelid. It was this method of handling errors in PHP:

do {
    code
    if ( error condition )
        break;
    code
    if ( error condition )
        break;
    code
} while ( 0 );
cleanup code

It seemed like a nice alternative to so many if trees and if/elseif/else hedges. It seemed so clean and obvious. It seemed too simple to have waited until 2007 to be imagined.

So I opened Firefox and typed “php goto” in the address bar (my new favorite way of searching recklessly) which led me to goto in PHP which linked to [PHP-DEV] GOTO operator (a 2004 discussion) and eventually a message from Andrey Hristov containing the very same idea. The thread goes on and on. Andi fights it hard, Rasmus drops in with a favorable opinion, and then everyone ignores him until I get tired of reading and go back to bed.

Epilogue: While reading, I recalled having seen what was basically the same idea in the PHP manual page for do-while loops.

PHP Object Hierarchies

Ever since I wrote the first draft of the Widgets plugin, I've had a fetish for structuring data as object hierarchies in PHP. There is so much you can do with such tiny snippets of code, why wouldn't you want to represent things that way? Some minds call it "too complicated" while others, like mine, consider it the peak of simplicity. Continue reading PHP Object Hierarchies