Is there anyway to detect when an error has occured in PHP and output it, currently the server settings are not to display any errors.
http://www.onlamp.com/pub/a/php/2003/10/09/php_foundations.html Provides a good example of an error handler
http://uk.php.net/manual/en/ref.errorfunc.php Some useful stuff in the manual, on error handling. If you just want to display errors and the php.ini has them truned off, then put this at the start of the file in question: PHP: <?php error_reporting(E_ALL); ?>
Actually, that won't work. If display_errors is set to off in php.ini, errors are off and that's it. error_reporting() only sets the level of error reporting, it doesn't explictly turn it on or off (ok... setting to E_NONE or whatever will effectively turn it off). Doug, the best way to do what you want is to (if Apache is checking for .htaccess files (via the AllowOverride directive)) give php a hint like so: <Files /path/to/my/php/file.php> php_flag display_errors on </Files> which will over-ride your php.ini setting. If you want to apply that to more than one php file, repeat the Files directive for the files you wish to display errors and notices in. And you can apply that to the entire directory by omitting the Files directive(s). If you can't use .htaccess you're SOL unless you can change the php.ini setting. Try Fuzzy's method, but again, I'd guess that if display_errors is off then even hooking php's error reporting function may be fruitless for ya. It is worth checking that avenue out though HTH
It's worth noting that some hosts let you have a custom php.ini file for a given directory. I'm not quite sure how it works, but if your host supports it, just place a php.ini file containing the "display_errors on" line (or whatever it exactly is) and you should be OK. I've tried setting reporting to E_ALL and got nothing locally, as I had no idea that reporting was apparently off. So basically you should check in with your host and see if they'll allow custom php.ini settings, and how you would go about doing it. They may or may not, but I'd say RTT's method is better if it's an option.
That is actually a damn good point. On a related note, MySQL checks a number of locations, including user home directories for my.cnf files I suspect though based on Doug's previous posts that this might be work related rather than commercial web hosting type stuff (and what host would disable errors?*) *probably a good host** ** do they exist?
considering its the Alpha dev server at work (beta for primary testing, delta secondary before actual release) I'm suprised that they haven't got warnings set. I eventually played around with the code to make the functions run from command prompt and found the errors out that way. Incidentally, the CLI method also doesn't have the File handling problems from my other post.
which also doesn't work in this case Fatal errors will be produced (and not shown, due to display_errors being off) before php has a chance to apply ini_set()