TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Muting errors in PHP5 (http://www.talkphp.com/general/3028-muting-errors-php5.html)

Ross 06-29-2008 04:11 PM

Muting errors in PHP5
 
My bad - I missed my missing semicolon :P

Just come across something very confusing. In PHP4 we could mute errors caused by a function by using @function().

I'm using PHP5 on this server and I get:

Quote:

Parse error: syntax error, unexpected '@' in /home/sites/***.co.uk/public_html/***/includes/class_registry.php on line 25
Lines 24-25:
PHP Code:

$config_file DIR '/includes/config/configuration.php'
@require_once($config_file); 

Now I'd assume PHP would throw an error notifying this doesn't work - I have errors set to E_ALL - rather than a parse error and I can't find anything on php.net - any ideas?

mfolnovich 06-29-2008 08:18 PM

for me it works ...
try with include_once($config_file); ...

xenon 06-29-2008 10:30 PM

Yes, you did miss your semicolon :-P However, this thing you're doing it's not called 'error muting', it's called error suppression. What's really happening is this: the error is still thrown in the back, except it's not shown to you. That's why this is bad and you should rather use error_reporting to control when and what errors to show. Oh, and because it's global. You don't have to set error_reporting before any statement, you just put it in the beginning of the script and that's it. You can, however set error reporting to a certain level until some point of your script, then change its value (turn it on/off depending on the case). Not the case with error suppression, where the @ must be in front of EVERY statement that throws some kind of error/notice/warning.

Ross 06-30-2008 08:12 AM

Quote:

Originally Posted by xenon (Post 16178)
Yes, you did miss your semicolon :-P However, this thing you're doing it's not called 'error muting', it's called error suppression. What's really happening is this: the error is still thrown in the back, except it's not shown to you. That's why this is bad and you should rather use error_reporting to control when and what errors to show. Oh, and because it's global. You don't have to set error_reporting before any statement, you just put it in the beginning of the script and that's it. You can, however set error reporting to a certain level until some point of your script, then change its value (turn it on/off depending on the case). Not the case with error suppression, where the @ must be in front of EVERY statement that throws some kind of error/notice/warning.

Thanks for your reply. So supposing I didn't want to display any PHP errors on a production system (obviously) - I could use errr_reporting(E_ALL) to show them to logged in Administrators?

Thanks for this - didn't realise I was following a bad practise!

drewbee 06-30-2008 03:13 PM

Quote:

Originally Posted by redSHIFT (Post 16186)
Thanks for your reply. So supposing I didn't want to display any PHP errors on a production system (obviously) - I could use errr_reporting(E_ALL) to show them to logged in Administrators?

Thanks for this - didn't realise I was following a bad practise!


Personally... I turn error reporting completely off for production systems. Error reporting should be used for development purposes, then if anything should go amiss properly capture the error and display a generic 'error has occured' page.

Although only turning it on for administrators and not general users is a better idea then jut turning it on for everyone. Hackers and malicious users tend to look for these error messages to give them clues.


All times are GMT. The time now is 05:37 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0