Accelerating PHP program development with Pear

Source: Internet
Author: User
Tags error handling file system functions install php net new features variables zend
The process of delivering applications in a timely manner is key to determining what technology the solution is using, with the help of the pear (PHP Extension and application repository:php extension and application Library) that greatly facilitates its development. Pear is a code base that provides a predefined class for standard program functionality, which greatly reduces the development time of the application. Pear's conceptually similar to Perl's Cpan,pear contains rich features of functional functions, including databases, mail, and error handling. In the case of pear, developers can deploy and enhance the basic functions that have been written while focusing on writing new features.

Pear Basics
The purpose of creating pear is to provide a standardized way for developers to share PHP code and facilitate the reuse of code. The project is always in the process of being developed, and users can submit their own code for use in the Pear Library, which is bundled with PHP. All pear packages adhere to the coding rules in the context of syntax and readability, which are composed of PHP or PHP extensions written in C language.

Stig Bakken started developing the Pear project later in 1999. His goal is to create an organized code base that acts as a repository for the PHP developer community. The project has grown very fast over the past two years and now contains quite a lot of useful reusable code. Although other PHP code libraries are quite well-known, such as Zend's Code Gallery and PHP Builder's source code snippet library, and so on, pear provides a convenient standard for interoperability between functions. In addition, the code submitted to pear is subject to rigorous scrutiny, which guarantees the quality and reliability of the code by such standards and checks.


Useful Web Sites

Pear Web site
Php.net
Concurrent versions System
Zend




Available Features
Pear is divided into three categories: the Pear core component, the pear package, and the PECL package. Core Component includes the base classes for pear and pear_error, as well as databases, HTTP, logging, and e-mail functions. The pear package includes functions that provide authentication, networking, and file system features, as well as tools that use XML and HTML templates. The PECL package is an extension of PHP that is written in C and does not conform to coding rules. At present, all this kind of code is experimental. To learn more about pear features, please refer to the Pear online manual.

If you are interested in submitting code to pear, you can add the Pear Developer Mailing list and ask you to check your code to achieve the above. However, you should note the functions that are already included in the library and follow Pear's coding rules.

From where to get pear

Pear is bundled in the PHP release package, and when you install PHP, you also have pear installed. If you're going to get a stable version and you can survive without the latest pear version, you can get the latest PHP version from the php.net download page. If you are adventurous and want to use the latest version of pear, you can download it using the CVS client program as instructed by the anonymous CVS access.

After installing PHP, the PEAR resource is placed in the ~/php/pear/directory. You may want to add your PHP directory location to the php.ini include_path parameters (for example: include_path = ".:/ Usr/local/lib/php ";) so that you can use the Pear feature.

How to use Pear
All you have to do now is use require_once () where you use the function and the other classes you write. The example in listing a uses Pear's email feature sendmail. This section of the code illustrates the mail.php file in the Pear Library, which is an extension of the PEAR.php class.

Next, we set up some of the necessary variables, which are $recipients, $headers, and $body, which are required by all pear mail functions and $params. You can join the online Pear manual to find out how these variables are set up. There is also a lot of information in the comments in the Pear code itself, but in general, the site is the most helpful to you.

Finally, the sample code calls the Pear Mail class. First, we use the Mail::factory method in the ~/php/mail.php file to include the appropriate class file for the mail driver, in our example SendMail (located in the ~/php/mail/sendmail.php file). We then actually invoke the mail-sending function from the Pear Mail class. When we instantiate the Mail class with a reference (=&) We can reference the class by reference name $mail_object.

If you want to know the usage of the Pear db function, you might as well go to the Quick Start Guide to Pear DB, which is maintained by Tomas V. Cox.


Why Use Pear
As noted above, the Pear feature is simple to deploy without the need for additional programming. Although we can achieve the same result with PHP's intrinsic functions, deploying the Pear module can immediately bring us practical benefits of error checking, while also facilitating the reuse of programs.

In addition, more and more advanced applications are starting to use pear, and pear's code base is growing. Because pear is included in the PHP license, you can use or modify the function you choose for free. Also, you don't have to rewrite the Numb authentication module again, which is a very attractive benefit for developers, and you can enjoy the great benefits of custom development.


A lot of good.
With qualified pre-programmed, reusable code, you can dramatically accelerate the development cycle of your application without having to overdo it with technology choices. Pear is the fruit of the effort by the PHP community to facilitate developers, and it provides a complete set of ways to implement a good application. Using the Pear code and making its contribution to it not only accelerates project delivery time, but also enables the development of better quality applications today and in the future.

TechRepublic is an online community and resource Center for all types of IT professionals, and we provide in-depth technical articles written by IT experts, facing readers of IT specialists. In addition to providing a variety of articles from Windows to e-mail to firewalls, we also provide IT industry analytics, downloads, Management Essentials, discussion groups, and news mail services.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.