PEAR Articles
  Home arrow PEAR Articles arrow Page 4 - The PEAR Package Tour: PEAR Basics
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PEAR ARTICLES

The PEAR Package Tour: PEAR Basics
By: Chris Moyer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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


       · Thanks for reading my PEAR article. This is the first of a series, with others...
     

    PEAR ARTICLES ARTICLES

    - 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
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT