New Releases!

It’s been a busy weekend playing catchup on bug reports and feature requests. These projects of mine have seen new releases yesterday and today as a result:

* Contact_Vcard_Build 1.1.1 (bugfixes)
* Contact_Vcard_Parse 1.31.0 (bugfixes)
* DB_Table 1.0.1 (bugfixes)
* Savant3 dev 4

The new Savant release bears a little talking-about. I don’t like breaking backwards compatibility even in a development release if I can help it, but there was one issue that required an architectural change related to error handling. That is the removal of error-handling resources (e.g., Savant3_Error_pear, et. al.), which is pretty significant if you use it. (Exceptions are a special case; see below for more on that.)

The original purpose of having error-handling resources was so that you could report and test for errors using your own framework-specific calls. While the Savant3 error resources would allow you to plug into those systems, the number-one complaint I got was that Savant3 still returned errors as Savant3_Error objects, which meant that you had to use Savant3 to check for errors, not the framework-specific error checker. That’s obviously a problem, as it doesn’t meet the original goal of being able to abstract error reporting and testing.

As a result, I have removed the error-handling resource infrastructure. Instead, if you want to use framework-specific error reporting and testing, you should extend Savant3 and override the error() and isError() methods. For example, if you wanted to use PEAR_Error handling, you would do something like this:

include_once 'Savant3.php';
class Savant3_Pear extends Savant3 {

    public method error($code, $info = array(), $level = E_USER_ERROR,
        $trace = true)
        if (! class_exists('PEAR_Error')) {
            include_once 'PEAR.php';
        $err = PEAR::raiseError($code, $code, $info, $level);
        return $err;

    public function isError($obj)
        if (! class_exists('PEAR_Error')) {
            include_once 'PEAR.php';
        return PEAR::isError($obj);

The difference between this and the previous (Savant2) error handler resource architecture is that the call to error() will return a PEAR_Error, not a Savant3_Error. In addition, while you can test for errors using the extended isError() method, you can use PEAR::isError() instead because the returned error object is a real PEAR_Error object. This applies to all frameworks that use their own error handling systems (which is, well, almost all frameworks, including Solar, which now bundles Savant3 as its default template system).

Exceptions are a special case; they’re native to PHP5, so they have native support in Savant3 now (instead of being an error handler resource). If you want Savant3 to throw exceptions, call setExceptions(true) and it’ll throw Savant3_Exception objects when errors occur.

For full change notes, be sure to visit the Savant3 website.

Are you stuck with a legacy PHP application? You should buy my book because it gives you a step-by-step guide to improving your codebase, all while keeping it running the whole time.

3 thoughts on “New Releases!

  1. Nice work, Paul! I wonder though: maybe you should create a few common extensions — such as the Savant3_PEAR class in your post, or Savant3_Solar — for some of the common frameworks, and distribute them as part of Savant3. This would prevent duplication of effort on the part of developers as they wouldn’t each be maintaining their own error classes, while simultaneously giving Savant3 the flexibility you were originally hoping to provide in your error class.

    Just a thought!

  2. Hi Matthew — that’s a good idea. I’m considering making separate packages of the Savant3 core and some of the plugins (notably the “form” plugin) … maybe separate packages for a Savant3_Pear and Savant3_PearError would be a good idea. Solar already bundles and extends Savant3, so a Savant3_Solar isn’t required: it already exists as Solar_Template.

  3. I use Savant in almost all of my apps and I am very happy to hear that you’ve changed error handling. I don’t use PEAR anymore when I code and it’s nice to not have to jerry-wrig a copy in my lib folder.

Leave a Reply

Your email address will not be published. Required fields are marked *