PHP Extension and Application Repository (PEAR)

In short, PEAR is a project designed to raise the bar for PHP developers and make everyone's life easier. In many ways PEAR for PHP is analogous to CPAN for Perl, although philosophical differences between PHP and Perl result in significantly different manifestations. The PEAR Web site ( defines its contributions to the PHP community as follows:

  1. A structured library of open-sourced code for PHP users
  2. A system for code distribution and package maintenance
  3. A standard style for code written in PHP
  4. The PHP Foundation Classes (PFC)
  5. The PHP Extension Code Library (PECL)
  6. A web site, mailing lists and download mirrors to support the PHP/PEAR community


At first glance, it looks like many other script repositories, but PEAR provides greater value by enforcing numerous standards on its submissions. This is where PEAR really differentiates itself from projects like CPAN. The desire for standards fits nicely with PHP's niche as a Web scripting language. Perl provides an extremely flexible core language, whereas PHP uses a more basic core language in favor of a huge number of built-in functions to perform common tasks. So while Perl users can benefit quickly from a large selection of modules, PHP users already have most of the building blocks they need, and benefit more by standardizing methods of completing common but sophisticated tasks.

PEAR could be considered the saving grace of PHP because it allows the language to grow without bloating the core which is what has always been the greatest danger facing PHP's future development. Although the client application has only recently hit version 1.0, it already ships in the default PHP 4.3.0 installation. Acceptance of PEAR may be a challenge given the added complexity of writing to the standards, but PEAR has already found a niche among many serious PHP developers if not the casual hobbyist.

Coding Standards

PEAR standards are based around a class/object model, PHPDoc documentation, and some formatting/naming guidelines thrown in for consistency. The object-oriented approach is questionable since PHP does not provide very robust OOP support. This also runs the risk of adding unneeded complexity to simple tasks. Yet for large projects requiring many modules, it seems like a reasonable way to keep things clean and organized.

Submitting Code

Developers wishing to contribute must submit their classes for approval must be willing to conform to the coding standards, submit documentation, provide maintenance (bug fixes), and release under a freely distributable and extendable license. Once a package has been prepared, it must be submitted for approval to the PEAR developers mailing list, where at least 5 developers must give a thumbs up for it to be included.

Foundation Classes and PECL

The Foundation Classes should be considered the core of PEAR. These are high-quality, broadly useful, interoperable packages with fixed APIs that are the cream of PHP code. For the developer wishing to take advantage of PEAR, these are the safest packages to use. PECL stands for PHP Extension Code Library which are actually not PHP at all, but C modules meant to provide higher-performance functionality to PHP. Any module could theoretically be ported from PHP to C, but it is mostly useful when increased efficiency is needed.

Using PEAR

PEAR can be a bit intimidating to use with all it's dependencies and complex classes. PHP is so easy to learn that PEAR may seem unnecessarily difficult to the novice PHP developer who may give up in frustration. This is merely an unfortunate side-effect of PHP's ease of use.

The good news is that for the PHP developer who wants to be taken seriously, PEAR offers the opportunity to reuse well-designed components and show that you are not just a scripting hack, but actually have what it takes to engineer quality software. If you're tired of being denegrated by Java and Perl programmers who think PHP is for script kiddies, this is your opportunity to use PHP's advantages to fullest extent. And if you maintain more than one site that use many similar but slightly different functions, PEAR may be able to offer you a lot of solid reusability. After using a few of the foundation classes, I promise you'll be hooked.