tags:

views:

90

answers:

6

What can I do to make my PHP web application fail in a more noisy way?

I am using an MVC pattern and often when classes fail to load or failures they do so without error.

A: 

Use the require_once method to load your files instead of include.

I think that's what you're asking, right?

Zachary Spencer
+1  A: 

Depending on what your error reporting level is at, you could try raising it via .htaccess.

php_value display_errors 1
php_value error_reporting 2147483647 
Greg W
A: 

If you're doing testing, check whether your php.ini settings has display_errors property turned on.

paul_sns
Also, please note that I mentioned "testing" because this setting should almost always be turned off in production as this might compromise security.
paul_sns
+7  A: 
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );
ini_set( 'log_errors', '1' );

function error_handler($errno, $errstr, $errfile, $errline) {
  system('/usr/bin/mplayer /home/user/music/Moras_Modern_Rhythmists/Mr._Ghost_Goes_to_Town.mp3', $retval);
  return true;
}

set_error_handler( "error_handler" );
?>
Dave Jarvis
Pretty cool. Imagine doing this on a colocated server (yes, I know they're not likely to have sound cards).
thomasrutter
Nor would `mplayer` be installed. ;-)
Dave Jarvis
If you have display_errors off in php.ini, you will not see errors outputted to the browser that prevent your script from executing, such as parse errors.
erisco
error_reporting( E_ALL );ini_set( 'display_errors', '1' );ini_set( 'log_errors', '1' );This was what I needed. Thank you.
Supermighty
You're welcome, Supermighty. Usually, as a small token of appreciation, you click the check-mark to mark this answer as correct.
Dave Jarvis
A: 
<?  ini_set("Melodramatic", "true"); ?>
jerebear
A: 

The easy answer: die('A fatal error occurred')

In a PHP application I wrote, I came up with a convention of using a variable or class member named $err_msg which is initially set to null . When an error happens, set it to a human readable string. When it's time to check errors, check $err_msg and put it on display for the end-user. If it's an AJAX call, echo $err_msg on failure, echo 'OK' on success.

In my case, I wrote a simple jQuery-based status box that can display busy indicators and errors. When an AJAX call returns an error message, I make the status box fade in with a red background and display the error message. It's quite nice and uniform.

Joey Adams
I use die() in places to help, but not everywhere.This helped me. It E_ALL generates more errors than E_STRICT.error_reporting( E_ALL ); ini_set( 'display_errors', '1' ); ini_set( 'log_errors', '1' ); Thank you.
Supermighty