PEAR Articles

  Home arrow PEAR Articles arrow Page 4 - The PEAR Package Tour: PEAR Basics
PEAR ARTICLES

The PEAR Package Tour: PEAR Basics
By: Chris Moyer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-07-09

    Table of Contents:
  • The PEAR Package Tour: PEAR Basics
  • Installing PEAR Modules
  • Installing Packages
  • Core PEAR Classes
  • A Selection of PEAR Packages

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    The PEAR Package Tour: PEAR Basics - Core PEAR Classes


    (Page 4 of 5 )

    PEAR includes a few core classes which are used by most packages to standardize the interface. These include a class for interacting with PEAR itself, error and exception management, and a System class which provides improved cross-platform support for file system operations.

    Of these classes, the most important is PEAR and its error handling. This is the primary behavior that you’ll need understand and deal with when consuming PEAR packages in you applications. Nearly every function or method in a PEAR package that can fail, will utilize the PEAR error handling. This is done through the PEAR base class and the raiseError() method.

    function pearMethod() {

    if ($somethingWentWrong) {

    return PEAR::raiseError(‘Something went wrong’);

    }

    }

    Calling code should check the returns form PEAR modules with the isError() method.

    $result = pearMethod();


    if (PEAR::isError($result)) {

    die(‘Uh Oh! ‘ . $result->getMessage());

    }

    This allows a programmer to always know how to handle possible errors from the PEAR packages. For recent PHP5 only packages, PEAR provides an exception class with a similar purpose.

    function pearMethod() {

    if ($somethingWentWrong) {

    throw new PEAR_Exception(‘Something went wrong’);

    }

    }


    try {

    $result = pearMethod();

    }

    catch (PEAR_Exception $e) {

    die(‘Uh Oh!’ . $e);

    }

    More PEAR Articles Articles
    More By Chris Moyer

    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap