In the following series of articles, we are going to be exploring PEAR: what it is, how it works, and how widely it is supported. Then we are going to build an application to see how it is used. The best part of the PEAR package is that it comes free with PHP. Personally, Iím very impressed by the way in which PEAR makes it easy to integrate different types of databases. This feature along with many others is what makes this repository so very useful.
What is PEAR?
PEAR is an acronym for PHP Extension and Application Repository. It was set up by a PHP developer called Stig Bakken in 1999. The main reason for setting up this repository is to provide an officially sanctioned library of open source components contributed by PHP developers from all over the world, as well as to establish a commonly accepted way for installing those components into installations of PHP. In other words, this repository was created to make life easier for us PHP developers, and with much success.
Many of the features that are available in PEAR are borrowed from the Comprehensive Perl Archive Network, or CPAN. In fact there are a lot of similarities between the two, especially in the areas of detection and installation of dependent modules. As you will no doubt notice, the packages that are contained in PEAR cover a wide variety of functionality. These include databases, support for reading and writing a variety of file formats, and HTML and XML support.
To better understand PEAR, let's look at its structure contents:
Each area of functionality is represented by a package. Thus PEAR has a variety of packages.
The PEAR Manager is used to remove and install packages from a PHP installation
PHP Foundation Classes (PFC)
All packages that are contained in PEAR are distributed in classes. This makes them highly re-usable, so an object-oriented methodology makes a great deal of sense.
A quick word on PHP Foundation Classes, or PFCs. Basically PFCs offer a variety of functional routines that go beyond the basic functionality of PHP. This means that they offer even more functionality on top of that which is offered by your version of PHP. Some of the foundation classes that are included in PFC are the OS Guess class, the Mail Class, etc. Simply check your PEAR directory to see which foundation classes have been included. The PHP Foundation Classes are updated as and when a new version of PHP is released.
The PHP Extension Community Library, or PECL, like PHP Foundation Classes, is also another subset of the PEAR repository consisting of components written in C. The reason for components such as these is the need for speed. Components written and compiled in C work a lot faster than, say, a language like PHP. This is especially true when it comes to mathematically intensive ops. PECL provides component developers with the speed and power of C while offering an interface to those components through standard PHP syntax. Though PECL is now a project on its own, it still retains the layout of PEAR. PECL is located at http://pecl.pear.net/
The other main component of PEAR is the Package Manager. As stated before, the main purpose of this component is to install and remove PEAR packages with ease. Perhaps one of the most noticeable things about the Package Manager is that it is dependency aware. This means that, when you install a particular package that is dependent on one or more other packages, it kindly installs those dependent packages for you. It is also aware of the hierarchy of dependency, so it ensures that those packages are installed in the correct order. This is an especially useful feature because most of the packages that are included in the PEAR repository have dependencies.