When i do a redirect, no errors are shown.
I use codeigniter framework and there’s
error_reporting(E_ALL);
ini_set('display_errors', 1);
in my index.php file.
When something is breaking in my code(e.g.some ‘undefined index’ error) and i do a redirect to another page – the error isn’t showing. How to avoid this – break the redirect and show the errors?
redirect function is just a simple header:
header('Location: ' . $uri);
I’m assuming this is something connected with output buffers. I’ve tried to turn on buffer(in index.php) using ob_start() but nothing happens.
Thanks.
The approach I take it to use a custom error handler which throws exceptions on any error; this makes sure I don’t miss anything during development. Throwing the exception will cause your code to abort immediately, therefore avoiding the redirect. For the production sites, I disable this (and also disable display_errors, of course). I’ve included simple code to do this below.
Note that this should be done as early as possible in the execution of your script, to catch all errors. Note also that the error_reporting() call may cause too many errors to be reported for your liking; we develop to a very strict standard and I find that throwing exceptions even for E_NOTICE type errors saves me a lot of pain down the line, but it’s up to you.