Home arrow PHP arrow Page 9 - Building A Generic Error Reporting Class In PHP

Going To The Source - PHP

The traditional method of building dynamic, PHP-based Web sites - mixing HTML elements with PHP code - can result in mangled Web pages (and much user angst) if errors take place during script execution. But yes, you can avoid the ugliness - plug in our handy error reporting class, which provides a simple way of trapping script errors and generating consistent, user-friendly error screens.

TABLE OF CONTENTS:
  1. Building A Generic Error Reporting Class In PHP
  2. Back To Class
  3. The Bare Bones
  4. How Things Work
  5. The Number Game
  6. Running On Empty
  7. Raising An Alarm
  8. A Well-Formed Idea
  9. Going To The Source
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 21
December 11, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Of course, this is just my first stab at a generic error reporting class. It's designed for very simple requirements, and may be way too primitive for your needs. If this is the case, you have two basic options:
  1. File the results of my efforts in the trash can and write your own, much-cooler, does-everything-but-make-toast class;
  2. Pick up a free, open-source PHP class which offers a more powerful feature set.
If you picked door one, you don't really need my help any more. You can stop reading right now and get to work. Have fun, and remember to send me a Christmas card if you sell your software for a million bucks.

If, on the other hand, you're lazy and figured that door two was more promising, you'll be happy to hear that the Web has a huge number of powerful error handling classes floating around it, many of them extremely powerful. Here are two that looked particularly interesting:

Gyozo Papp's ErrorHandler class, at http://gremlins.mirrors.phpclasses.org/browse.html/package/345.html

Lennart Groetzbach's debugHelper class, at http://gremlins.mirrors.phpclasses.org/browse.html/package/891.html

You can also read more about the material discussed in this article, at the following links:

PHP output control functions, at http://www.php.net/manual/en/ref.outcontrol.php

PHP error handling functions, at http://www.php.net/manual/en/ref.errorfunc.php

Classes in PHP, at http://www.php.net/manual/en/language.oop.php

And that's about all for the moment. In this article, you expanded your knowledge of PHP's OOP capabilities by actually using all that theory to build something useful - an error reporting widget which can be wrapped around your PHP scripts to provide consistent and reusable error messages without breaking your Web pages.

If you're a stressed-out Web developer working on a Web site or application, you might find this object a handy tool in your next development effort. If you're a novice programmer struggling to understand how OOP can make your life easier, I hope this article offered some pointers, as well as some illustration of how object-oriented programming works. And if you don't fit into either of those categories - well, I hope you found it interesting and informative, anyway.

See you soon!

Note: All examples in this article have been tested on Linux/i586 with PHP 4.2.3. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: