less than 1 minute read

Put the case that we would like to follow our learned design patterns while working on a well OOP’ed project, but in PHP. We need the finally statement to delete a lockfile in all cases, including an exception. I think it’s a good idea to implement this like the above:

$lockfile = "/temp/appname.lock"
try {
  // create the lockfile
  touch($lockfile)
  // some if's, writing to another file.
} catch(Exception $e) {
  // error handling
  echo 'Caught exception: ',  $e->getMessage(), "\n";
} finally {
  // remove the lockfile
  unlink($lockfile);
}

Today is 2010, one year after the release of the PHP 5.3, we still don’t have real OOP feeling when coding in PHP. The feature request of the finally statement is dated to 2005, and today, a PHP developer wrote to this request the following:

The lack of finally causes us some crufty hard to debug code.

LOL, I can’t understand why this language is the most popular in web development field.

UPDATE: finally we have finally statement in PHP 5.5: http://www.czettner.com/blog/13/05/24/new-features-php-55

Updated:

Comments