Speed PHP development with PEAR

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.

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

bordero

ike fuelband is great for every healthminded person ! to work out! theres this website called textme4free.com that you can use to text anywhere in...

7 hours ago by bordero on Nike's FuelBand wristband gamifies exercise
BrownieBoy

> I'm told it's somewhat annoying when people have their Macs stolen > and Apple stores treat the thief as the owner, but there you go. Ouch,...

9 hours ago by BrownieBoy on AMD Ultrathins to challenge Intel Ultrabooks
Moley

@kevinmchapman. OK, I acknowledge that 'most' was a gratuitous throwaway comment as an afterthought and too presumptuous. As to proof, as you...

14 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
Jack Schofield

@BrownieBoy > Works really well for thieves.... >> Nice attempt to deflect the argument by tossing in a point that's totally >> irrelevant, even...

15 hours ago by Jack Schofield on AMD Ultrathins to challenge Intel Ultrabooks
raskolnikof

fantastic that the so called piracy bills have been withdrawn. however, these anti-democracy supporters are still in the shadows so lets be alert...

15 hours ago by raskolnikof on SOPA, Protect IP support wavers in face of online protest
Tony Douglas

Please God no; teach them anything you like - thinking rationally, the uses and misuses of data, what data is and what it's not - but leave the...

18 hours ago by Tony Douglas via Facebook on Kids are the future. Teach ’em to code.
BrownieBoy

@Jack, > Works really well for thieves.... Nice attempt to deflect the argument by tossing in a point that's totally irrelevant, even it were...

1 day ago by BrownieBoy on AMD Ultrathins to challenge Intel Ultrabooks
bootlegger

Make that 13 people now - I got refused today at Manchester airport. I thought I was up to date on this legislation - I knew of the EU ruling from...

1 day ago by bootlegger on UK airport body scans will not be opt out
tinycg

Don't forget to check out apps like GoodReader or SlideShark either, they're indispensible for people on the go in presentation situations. Best...

2 days ago by tinycg on Four top iPad apps for people on the move
TerryRK

Well it seems there is something a number of us agree on. Why is the Ubuntu Unity launcher so ugly? I thought perhaps it was something to do with...

2 days ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
Freebies202

Duplicate comments are not made intentionally. Its very good to know that now you are keeping check on this problem because sometimes a commenter...

2 days ago by Freebies202 on Microsoft fixes blog comments, speeds up blogs with open source
kevinmchapman

"the very significant number of users" and "many (most) of us" - you have no evidence for these statements. It is a fact that most users are saying...

2 days ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
Marg Menzies Harrison

Another grammar faux pas is the improper use of "you". When sitting down down in a restaurant, for example, I get cringe when the waitress...

3 days ago by Marg Menzies Harrison via Facebook on 10 flagrant grammar mistakes that make you look stupid
zdnetukuser

And NOW, folks, for Canonical's next trick... Kubuntu is late. Here's a pencil. Draw your own conclusions. cf.:...

3 days ago by zdnetukuser on Linux Minterface
Moley

@kevinmchapman. The discussion here reflects the very significant number of users who really do like the traditional menu system and who wish to...

3 days ago by Moley on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

Er, no... It is an efficient means of finding the application/file/setting you need in one place. The icons are a simply a fallback for when you...

3 days ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

Isn't the provision of a text based search an admission by the developers that the mass of icons approach does not work? I don't need to use a...

3 days ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

"Unity and GNOME 3 both abandon the old text-based cascading menus in favour of a graphical icon-driven system." Point truly missed. Both use a...

3 days ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

whs001 - Thank you, I'm glad you liked the article. I absolutely agree with you on your first point. I should perhaps have made it clearer that...

3 days ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
Dennis Nilsson

If we allow corporate interest to dictate the way our government circumvents due process against foreign entities then we should accept the same...

3 days ago by Dennis Nilsson via Facebook on ACTA stumbles in Germany

Latest in Application Development