Building A Generic Error Reporting Class In PHP - Going To The Source
(Page 9 of 9 )
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:
- File the results of my efforts in the trash can and write your own, much-cooler, does-everything-but-make-toast class;
- 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!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |