View Full Version : warning messages division by zero
01-02-2007, 12:01 PM
I have an application that does some maths, sometimes a zero will appear and thus the php creates bold warning message about the zero division .. though the code is fine...
does anyone know a way to hide all non-fatal warning messages?
Sir P :D
01-02-2007, 12:26 PM
How about using the error_reporting (http://php.net/manual/en/function.error-reporting.php) function at the beginning of your script:
Alternatively, the @-operator (http://www.php.net/manual/en/language.operators.errorcontrol.php) might suffice for preventing warning message for the single statement:
@$a = 5/0; // no warning displayed
01-02-2007, 01:06 PM
If you get division by zero errors then there is something wrong in the code as a whole.
01-02-2007, 01:09 PM
hi both, thanks for the error reporting link.. took out the messages. Ta.
Mar, thanks for your reply. The warning does not mean that I'm dividing a value that is 0? ... The maths formula I have sometimes has a 0 passed to it... and still gets devided, Are you sure it is a code thing and not just that the value is 0?
01-02-2007, 01:58 PM
better off to check first..
01-02-2007, 03:40 PM
cheers firepages.. i have considered checking however it is right bang in the middle of quite a complex string of maths ...
So php gives you a warning about it, does that mean having it in there causes problems? I don't see too much of a problem?
01-02-2007, 07:20 PM
Is getting wrong results not a problem for you?
01-03-2007, 12:14 AM
Even supressed with an '@' the error has to be handled internally by php (including telling itself to not create the error report) so its probably just as efficient (and certainly `cleaner`) to do the check.
I used to use @ a lot, these days I feel compelled to do the checks as above.
01-03-2007, 09:22 AM
Mar, no not really seeing as the division in the formula is a small part of the formula, dividing by 0 just makes a zero which is not an error, just a lower result so it is no problem that I see.
Thanks again all much apperciated
01-03-2007, 03:00 PM
Well in real math the result of your mathematical function would be undefined and not "just a lower result" so you should check if you are counting, whatever you are counting, correctly.
I just want to say that that little difference can be very important, and checking that the argument(s) are in the function's domain will allow you to skip some calculatons as you will be sure of the result.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.