ZDNet UK


Skip to Main Content

ZDNet.co.uk - Winner of Best Business Website 2007
  1. Home
  2. News
  3. Blogs
  4. Reviews
  5. Prices
  6. Resources
  7. Community
  8. My ZDNet

 

ZDNet UK RSS Feeds


Application development Toolkit

Speed PHP development with PEAR

Shelley Doll Builder.com

Published: 22 Oct 2002 09:57 BST

  • Email
  • Trackback
  • Clip Link
  • Print friendly
  • Post Comment

Where to get PEAR
PEAR is bundled with the PHP distribution, and it's installed when you install PHP itself. If you want to be assured of a stable release, and you can live without the latest PEAR version, you can get the latest full PHP release from php.net's download page. If you're more adventurous and would like the latest version of PEAR, you can download it with a CVS client by following these instructions for anonymous CVS access.

Once you've installed PHP, the PEAR resources will be located in the ~/php/PEAR/ directory. Add the location of your php directory to your php.ini include_path parameter (example: include_path = ".:/usr/local/lib/php";), and you're ready to use the available PEAR functionality.


How to use PEAR
Now all you need to do is require_once() whichever functions you'll be using, as you would any other class you had written yourself. The example in Listing A makes use of PEAR's e-mail features using Sendmail. The code instantiates the Mail.php file in the PEAR library, which extends the class PEAR.php.

Next, we set some expected variables -- $recipients, $headers, and $body -- which are required by all PEAR Mail functions, and $params. You can find out what variables to set by referring to the online PEAR manual for the desired function. There is also information within the comments of the PEAR code itself, but generally speaking, the Web site is more helpful.

Finally, the sample code calls the PEAR Mail class. First, we use the Mail::factory method within the ~/php/Mail.php file to include the appropriate class file for the mail driver -- in our case, Sendmail (located in the ~/php/Mail/sendmail.php file). Next, we actually call the send function, from within the PEAR Mail class. By using a reference ( =& ) when we instantiate Mail, we can now refer to it via the reference name, $mail_object.

Should you find yourself using the PEAR DB functions, one great resource is Quick Start Guide to Pear DB, by Tomas V. V. Cox.

Why use PEAR?
As shown above, PEAR functionality is easy to deploy and requires no additional programming. While we could have used PHP's native functionality to achieve the same result, deploying the PEAR module gave us the immediate benefit of error checking, and it facilitated portability.

Additionally, more sophisticated applications are available via PEAR, and the code base grows continuously. Because PEAR is included in the PHP license, you are free to use or tweak whatever functionality you choose. Also -- and this is probably the most appealing benefit for developers -- you'll never have to face the mind-numbing frustration of writing yet-another-authentication module, yet you can still enjoy the benefits of custom development.

Plenty of benefits
By using quality prewritten, reusable code, you can tremendously shorten your development cycle without having to compromise your choice of technology. PEAR is an effort by the PHP community to benefit developers by providing the means for implementing competitive best practices. Using and contributing to the PEAR code base improves project delivery times and makes for better applications, now and in the future.


Have your say instantly in the
Tech Update forum.

Find out what's where in the new Tech Update with our
Guided Tour.

Let the editors know what you think in the
Mailroom.

Next

Previous

1 2


  • Email
  • Trackback
  • Clip Link
  • Print friendly
  • Post Comment

Did you find this article useful?
72 out of 175 people found this useful


Full Talkback thread

0 comments

Company/Topic Alerts

Create a new alert from the list below:








Discussions

Jim Mader Jim Mader

Hotmail

Friday 29 August 2008, 12:28 AM

4 comments
da9938k da9938k

same thing happened to me!!

Thursday 28 August 2008, 11:20 PM

3 comments
da9938k da9938k

same thing happened to me!!

Thursday 28 August 2008, 11:20 PM

3 comments
da9938k da9938k

same thing happened to me!!

Thursday 28 August 2008, 11:20 PM

3 comments

Featured Talkback

The fact is: Software developers today are really designers and not coders. The reason that business anlaysts exist today to model solutions is because they understand the value of designing software before writing it. All too often developers create code that has little value because they do not understand that business classes interact with other classes within the confines of a working model or pattern.

By: 1000165269

Read full story:
Making sense of agile modelling