PEAR:: Classes Worthy Of Attention

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?

The Social Box

You can sign up for more updates via Twitter or Facebook below. On Twitter, I regularly talk about technology or tweet about interesting stories. Topics that don't necessarily make it to this blog. Facebook contains a steady update of blogposts and some more lightweight stories.

The @mattiasrss account has an automated RSS feed of all blogposts that get published.




Write a Comment

Do you care about the markup if your comment? You can use the following HTML tags:

<code>command</code>: command highlighting
<pre>text</pre>: pre-formatted code, can be multi-line (black background, white letters)

example <pre> tag
<blockquote>text</blockquote> quoted text
quoted example


None of this is needed of course, it's all optional!

Comment

*

  1. If PEAR can do it, why reinvent the wheel?

    I use the following:

    Config
    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)
    HTML_TagCloud
    HTML_Template_IT
    HTTP_Upload
    MDB2 / MDB2_Driver_mysql
    Mail / Mail_Mime
    Pager
    Services_YouTube
    Validate
    XML_Serializer
    tidy

    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.