• Categories



  • Archives

  • Note to self: PHP object constructors never return false

    Published June 13th, 2008

    As part of my ongoing refactoring work (see previous post) and having decided to take a more active stand against broken windows syndrome I’ve been cleaning up various coding oddities as I’ve found them.

    Today I came across (something like) this little snippet:

    if( ! $obj = new myObject( $id ) )
    {
      throw new Exception( 'Not a valid object' );
    }
    

    At first glance we might assume that the constructor attempts to populate the new object with some data loaded from (say) a database, but if no data matching the supplied ID is available, then the constructor returns false to indicate this. All very reasonable, right?

    Except that it’s not possible to return false, or indeed any value, from a constructor because the ‘return value’ of the constructor is the object itself. Which means that the above snippet is redundant, because the expression will always evaluate to true.

    It would’ve made more sense to throw an exception within the method that loads the data — and in fact this is exactly what happens, which makes the quoted code doubly redundant and even more inexplicable.

    I don’t think I’m the one who’s responsible for this particular brain fart but it’s OK because the only other likely candidate left the company last year so I happily can blame it on him…

    Screenshot web sites easily with FireShot

    Published June 11th, 2008

    Another day, another Firefox plugin plug…well I could drone on about how much fun it is to completely refactor all the exception handling in our large and complex publishing framework, but somehow I don’t think you’d be any more excited about it than I am.

    So I’ve been breaking up the monotony now and again by poking around Firefox’s ever-growing list of add-ons and yesterday I stumbled across Fireshot, which I think is easily good enough for a mention here. It’s a screen-grabber for Firefox, but in addition it also allows you, very quickly and easily, to annotate a screenshot, highlight areas of interest etc. You can choose to grab either just the visible area, or the whole page.

    I really am very impressed with how well thought-out and seamless it makes the process — very useful if you’re creating documentation, for example.

    One downside is that it’s Windows-only, which is a shame but understandable given that it’s based on (commercial) Windows software.

    Monitoring HTTP activity with HttpFox

    Published June 9th, 2008

    While Firebug is about as close to a perfect tool for web development as I’ve ever seen, its use as an HTTP monitor is limited — if only because its Net pane is cleared when the page refreshes. In the past I’ve used Fiddler for this job, but of course you need to remember to start it up and then configure Firefox’s proxy settings to make use of it.

    I’ve recently discovered HttpFox, a Firefox extension which sits quite neatly between the two: it works better than Firebug but lacks some of the more powerful facilities of Fiddler (for example, the ability to intercept and modify requests during send/receive). However for basic HTTP monitoring tasks, it’s simple and convenient.

    HttpFox in action (click for larger)

    Updated: Cross-platform browser testing

    Published May 22nd, 2008

    A while back I wrote an article about testing HTML on multiple browsers, bemoaning the difficulty of testing on platform-specific software such as Safari and Konqueror. Of course, since then Apple has released Safari for Windows, which takes care of that problem quite neatly.

    However, what of Konqueror? Putting aside the point that it’s very much a minority browser, the virtualisation options that I suggested in my previous article really are rather involved for what should be a simple ALT+Tab to browser / Refresh / Check page / ALT+Tab back to editor operation. And no virtualisation software I’ve yet tried offers any kind of acceptable performance on the frankly weedy PC I’m stuck with at work.

    So I was intrigued by Ulteo, which is a form of Linux designed to run as a ‘virtual desktop’ on top of Windows. Meaning that rather than running inside a self-contained window, applications running on Ulteo appear to be native Windows apps. Each has its own Windows taskbar icon (although XP’s grouping mechanism can rather spoil the effect) and can be accessed with ALT+Tab as if it were running on Windows itself. In operation, it’s entirely seamless: Ulteo itself manifests as a self-hiding application launcher at the top of the page, giving access to a whole range of Linux apps (including Konqueror).

    This screenshot shows Konqueror running alongside two instances of Firefox — Windows and Linux (click for larger version):


    Speed-wise, Ulteo takes a good while (on my wheezy old desktop) to boot up, but once it’s going it’s plenty fast enough that you wouldn’t really be aware that an app is running through Ulteo rather than Windows itself. It takes up its fair share of resources, but not so much that it interrupted the normal operation of my PC.

    It’s a decent compromise for a tricky situation and well worth a look if you’re interested in testing on Konqueror, or indeed just giving Linux a spin with the minimum of upheaval/effort.

    Flash 10 (beta) released, ex Flash developer feels his age

    Published May 15th, 2008

    OK so I haven’t really done much with Flash for a few years now but I’ll admit I was taken aback when I saw this morning that Adobe has released a beta of version 10. The tenth version!

    Don’t worry, I’m not going to get bogged down in all the nostalgia stuff. But looking at Flash now — with streaming audio and video, built-in 3D effects, advanced text manipulation and on and on — and thinking about some of the ‘amazing’ techniques that I (and others) experimented with back in the the day, makes me feel very old.