PEAR:: Classes Worthy Of Attention

Mattias Geniar, Monday, January 26, 2009 - last modified: Sunday, January 25, 2009

PEAR offers an excellent framework for re-usable PHP components. A wide range of PEAR classes is available, from XML Parsers to Captcha's and Mail components.

They're all easy to install, and have extensive documentation available so you can get started right away. Here's a list of some of the better, and probably lesser known ones.

  • PEAR::Mail
    PEAR's Mail package defines an interface for implementing mailers under the PEAR hierarchy. It also provides supporting functions useful to multiple mailer backends. Currently supported backends include: PHP's native mail() function, sendmail, and SMTP. This package also provides a RFC822 email address list validation utility class.
  • PEAR::XML_Parser
    This is an XML parser based on PHPs built-in xml extension. It supports two basic modes of operation: "func" and "event". In "func" mode, it will look for a function named after each element (xmltag_ELEMENT for start tags and xmltag_ELEMENT_ for end tags), and in "event" mode it uses a set of generic callbacks.
  • PEAR::MIME_Type
    Provide functionality for dealing with MIME types, such as auto-detecting MIME type on files.
  • PEAR::Net_Socket
    Net_Socket is a class interface to TCP sockets. It provides blocking and non-blocking operation, with different reading and writing modes (byte-wise, block-wise, line-wise and special formats like network byte-order ip addresses). It provides the base class for other popular PEAR-classes such as Net_SMTP and HTTP_Request.
  • PEAR::Archive_Tar
    This class provides handling of tar files in PHP.
    It supports creating, listing, extracting and adding to tar files. Gzip support is available if PHP has the zlib extension built-in or loaded. Bz2 compression is also supported with the bz2 extension loaded.

The list of available packages goes on for miles, and includes a Facebook package, a Number-to-Words convertor, Command line Argument Parser, CAPTCHA generator, Barcode Generator, ... Too much to mention!

For installation instructions, I'll refer you to the following two posts:

I'm interested to know what PEAR packages you're using, and why. Where do you draw the line between writing your own classes, and switching to PEAR's?

Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek, public speaker and podcaster. Currently working on DNS Spy. Follow me on Twitter as @mattiasgeniar.

I respect your privacy and you won't get spam. Ever.
Just a weekly newsletter about Linux and open source.

SysCast podcast

In the SysCast podcast I talk about Linux & open source projects, interview sysadmins or developers and discuss web-related technologies. A show by and for geeks!

cron.weekly newsletter

A weekly newsletter - delivered every Sunday - for Linux sysadmins and open source users. It helps keeps you informed about open source projects, Linux guides & tutorials and the latest news.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!


Daniel Wednesday, February 11, 2009 at 10:40

If PEAR can do it, why reinvent the wheel?

I use the following:

HTML_BBCodeParser – BB code for all user input
HTML_QuickForm – (and HTML_QuickForm_Renderer_Tableless) for form generation, it’s a bit dated and I’m waiting for HTML_QuickForm2 to progress further with development (poor support for renderers)
MDB2 / MDB2_Driver_mysql
Mail / Mail_Mime

My biggest complaint is only a few are E_STRICT compatible.

It makes development so much easier. I’ve even adopted the package method for my own framework.


Leave a Reply

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