I've been doing some thinking on exceptions, and PEAR_Exception in
particular. You may want to skip ahead to read about how to use
PEAR_Exception, as well as some of my thoughts on the class on first use. If
you want the background, read on.
I've created a package proposal on PEAR for a package called File_Fortune,
an OOP interface to reading and writing fortune files. I've been using a
perl module for this on the family website for years, and now that I'm
starting work on the PHP conversion, I thought I'd start with the building
blocks.
In creating the proposal, I started with a PHP5-only version, though I found
that I wasn't using much in PHP5 beyond the public/private/protected/static
keywords. For error handling, I decided to try out PEAR_ErrorStack,
as I'd been hearing buzz about it being the new "preferred" method for error
handling in PEAR. (Honestly, after using it, I'm not too happy with it;
throwing PEAR_Errors was much easier, and easier to manipulate as well --
but that's a subject for another post -- and exceptions were easier still,
though more typing.)
The first comment I got on the proposal was the question: "Why
PHP5?" (Paul wasn't too
surprised by that reaction.) I thought about it, and decided it wasn't
really all that necessary, beyond the fact that I'd need to take some extra
steps to be able to actually test a PHP4 version. So, I did a PHP4 version.
Well, then some chatter happened, and a number of developers said, "Why
not PHP5?" So, I went back to PHP5. And then somebody else said,
"Use PEAR_Exception." So, I started playing with that, and we finally get to
the subject of this post.