SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Make PHP exit on E_ALL|E_STRICT

    Hi all,

    I'd like to be able to make any script stop processing, basically exit(), whenever any type of error is discovered. For example, if I get an undefined variable error, the error will output, but the script continues to run. Is it possible to make the script to exit?

    Thanks!

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I think you can control it using try catch.
    Just play with it I guess.
    Quality codes are optimized and tested...
    Click here for inspiration..

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    That's not really an option for me since it would mean modifying loads of code. I was kinda looking for a quick solution. I've come across server environments before which stop on any kind of PHP error but I can't seem to find the right settings.

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,889
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Try searching for "PHP set_error_handler".

    Tapped in from a tablet
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Try this.

    Code php:
    set_error_handler(function ( $errno ,  $errstr, $errfile, $errline, $errcontext ) {
      echo "Error Number $errno: $errstr in file $errfile at line $errline.\n";
      print_r($errcontext);
      exit;
    });

    This traps ALL errors and sends a message, then dies immediately. You can get the error type by referencing the error numbers against the PHP error constants given here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •