Programming Basics

  Home arrow Programming Basics arrow Page 5 - Coding
PROGRAMMING BASICS

Coding
By: lig
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2006-01-17

    Table of Contents:
  • Coding
  • Thinking before Coding
  • Commenting
  • Coding Style
  • Error Reporting
  • Error Handling
  • Security
  • Reinventing the Wheel
  • Advanced
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Coding - Error Reporting


    (Page 5 of 10 )

    You can not fix an error if you don't know what it is. Believe it or not, being told of errors is a good thing, otherwise you would have a problem and no way of knowing there is a problem. PHP provides multiple ways of informing you of errors that occur in your scripts.

    php.ini

    There are a number of settings you can play with in the php.ini file that deal with error reporting. Settings made in php.ini affect ALL PHP scripts running on the server, not just yours. All the settings have documentation to help you customize it (check out the PHP manual). There is of course the error_reporting setting, but there is also display_error, log_errors, and the error_log settings. The display_error setting is just whether or not to display any error messages on the screen, which is typically set to false on production servers. Instead, error messages can be logged to a specific log file by setting log_errors and error_log.

    Script

    If you don't have access to the php.ini file that runs on your server--have no fear. You still can have some control over error reporting. The simplest way to make sure you can see all the errors in your specific script is to not suppress them with @. If you absolutely must use the @, add it AFTER all debugging and testing of your script. After that, set your scripts error_reporting() to E_ALL (or E_ALL | E_STRICT for PHP5). We can use the following example in our code to redirect all errors to a logfile outside a web accessible directory when we’re in production:

    <?php
    error_reporting
    (E_ALL E_STRICT);
    ini_set("display_errors"False);
    ini_set("log_errors"True);
    ini_set("error_log""../outside/of/web/root/error_log.txt");
    ?>

    More Programming Basics Articles
    More By lig

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap