PHP
  Home arrow PHP arrow Displaying Meaningful Error Messages w...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Displaying Meaningful Error Messages when Auto Loading Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-12-26

    Table of Contents:
  • Displaying Meaningful Error Messages when Auto Loading Classes in PHP 5
  • Establishing a Reference Point
  • Boosting the Existing Capacity
  • Developing a Final Example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Displaying Meaningful Error Messages when Auto Loading Classes in PHP 5
    (Page 1 of 4 )

    If you’re a PHP developer who wants to learn how to load automatically into client code all of the source classes required by your object-oriented applications, keep reading. In this series of articles, you’ll learn how to implement the magic “__autoload()” function that comes integrated with PHP 5. With this function, you'll be able to build scripts that can include automatically all of the classes needed by a given application, without using multiple “require()/require_once()” PHP statements.

    Introduction

    All right, now that I introduced you to the primary goal of this series of educational tutorials, I think it's time to recapitulate the themes covered in the preceding article. We'll refresh some key concepts concerning the correct use of the  “__autoload()” magic function in the context of a determined object-based application.

    As you’ll possibly remember, in that particular article I showed you how to improve the signature of the helpful “__autoload()” PHP 5 function to provide it with the capacity to throw an exception when a specific source class can’t be included into client code for whatever reason.

    In addition to adding this important feature to the function, I demonstrated how to introduce some “tweaks” into the signature of this function, with the objective of triggering exceptions that could be correctly intercepted within a conventional “try-catch()” block. In this way we would implement a powerful mechanism for loading automatically all of the classes required by a certain PHP 5-driven application, which also takes advantage of the built-in exception system offered natively by PHP 5. As you can see, in this case the best of both worlds is integrated seamlessly in the same magic function.

    Of course, if you reread the previous sentence, you might think that it simply isn’t possible to introduce more modifications to the “__autoload()” function anymore, which would mean that the topic wouldn’t bear any further analysis. Not so fast! Actually, it’s perfectly feasible to improve the way that the “__autoload()” function works even more. In its current incarnation it only is capable of displaying exception messages that aren’t very descriptive, such as “Class not found” or something similar.

    Indeed, it’s necessary to modify the logic of this function so it can throw exceptions that can be much more explicit and indicative of what’s going wrong when a particular source class can’t be included properly into client code. Thus, in this last article of the series I’m going to introduce some additional modifications to the current signature of the “__autoload()” function to make it throw exceptions that display more useful error messages.

    As you may guess, to learn how these improvements will be achieved, you’ll have to start reading this tutorial, so don’t waste more time; begin now!

    More PHP Articles
    More By Alejandro Gervasio


       · In this final part of the series, the implementation of the "__autoload()" magic...
       · 1. interesting solution but if you are using several different libraries with it's...
       · Thank you for posting your useful comments on my PHP article. Yes, as some other...
     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway