Re: [PHP] suppressing division by zero errors
On Thu, 2002-01-31 at 15:00, Martin Towell wrote: Is there a way to suppress division by zero errors? echo 5/0; // this give a warning - obviously!! @echo 5/0; // this gives a parse error echo @5/0; // this still comes up with a warning unless I turn error_reporting off before and turn it back on afterwards, but I don't want to do that unless I REALLY have to Martin The @ operator will work on the following expression in this case. In the last one above, you're suppressing the error from the expression '5', since the @ binds more tightly than the / (i.e. @ has a higher precedence). So you need to force precedence, which in PHP is done with parentheses: echo @(5/0); Check the following page for more information: http://www.php.net/manual/en/language.operators.precedence.php Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] suppressing division by zero errors
You really need to do some error checking on the denominator. $num = 5; $den = 0; echo $den != 0 ? $num/$den : 0; A number divided by zero isn't defined, so you have to circumvent the situation by making sure it never happens. ~Chris /\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden On Fri, 1 Feb 2002, Martin Towell wrote: Is there a way to suppress division by zero errors? echo 5/0; // this give a warning - obviously!! @echo 5/0; // this gives a parse error echo @5/0; // this still comes up with a warning unless I turn error_reporting off before and turn it back on afterwards, but I don't want to do that unless I REALLY have to Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] suppressing division by zero errors
I was thinking of writing a _very simple_ graphing program - enter an expression and php will generate an image with the graph on it, I didn't want to spend too much time parsing the expression up and seeing if there's a division or anything else that may cause an error/warning [eg tan(PI/2), etc] I know there's probably loads of code already written to do what I'm thinking of doing, but there's no substitute in starting from scratch and getting something working yourself :) Thanks Torben, that helped. Martin -Original Message- From: Christopher William Wesley [mailto:[EMAIL PROTECTED]] Sent: Friday, February 01, 2002 10:17 AM To: [EMAIL PROTECTED] Cc: Martin Towell Subject: Re: [PHP] suppressing division by zero errors You really need to do some error checking on the denominator. $num = 5; $den = 0; echo $den != 0 ? $num/$den : 0; A number divided by zero isn't defined, so you have to circumvent the situation by making sure it never happens. ~Chris /\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden On Fri, 1 Feb 2002, Martin Towell wrote: Is there a way to suppress division by zero errors? echo 5/0; // this give a warning - obviously!! @echo 5/0; // this gives a parse error echo @5/0; // this still comes up with a warning unless I turn error_reporting off before and turn it back on afterwards, but I don't want to do that unless I REALLY have to Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] suppressing division by zero errors
On Thu, 2002-01-31 at 15:26, Martin Towell wrote: I was thinking of writing a _very simple_ graphing program - enter an expression and php will generate an image with the graph on it, I didn't want to spend too much time parsing the expression up and seeing if there's a division or anything else that may cause an error/warning [eg tan(PI/2), etc] I know there's probably loads of code already written to do what I'm thinking of doing, but there's no substitute in starting from scratch and getting something working yourself :) Thanks Torben, that helped. Martin Just to warn you, I just checked this on PHP 4.0.3pl1 and it doesn't appear to suppress the warning, for some reason. Works on 4.2.0-dev though... Torben -Original Message- From: Christopher William Wesley [mailto:[EMAIL PROTECTED]] Sent: Friday, February 01, 2002 10:17 AM To: [EMAIL PROTECTED] Cc: Martin Towell Subject: Re: [PHP] suppressing division by zero errors You really need to do some error checking on the denominator. $num = 5; $den = 0; echo $den != 0 ? $num/$den : 0; A number divided by zero isn't defined, so you have to circumvent the situation by making sure it never happens. ~Chris /\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden On Fri, 1 Feb 2002, Martin Towell wrote: Is there a way to suppress division by zero errors? echo 5/0; // this give a warning - obviously!! @echo 5/0; // this gives a parse error echo @5/0; // this still comes up with a warning unless I turn error_reporting off before and turn it back on afterwards, but I don't want to do that unless I REALLY have to Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] suppressing division by zero errors
On Thu, 2002-01-31 at 15:16, Christopher William Wesley wrote: You really need to do some error checking on the denominator. $num = 5; $den = 0; echo $den != 0 ? $num/$den : 0; A number divided by zero isn't defined, so you have to circumvent the situation by making sure it never happens. Actually, the result of a divide-by-zero will be boolean false in PHP 4. Though in older (4.0.3pl1, to be precise) versions, the warning doesn't seem to be suppressable. Hm. Torben ~Chris /\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden On Fri, 1 Feb 2002, Martin Towell wrote: Is there a way to suppress division by zero errors? echo 5/0; // this give a warning - obviously!! @echo 5/0; // this gives a parse error echo @5/0; // this still comes up with a warning unless I turn error_reporting off before and turn it back on afterwards, but I don't want to do that unless I REALLY have to Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] suppressing division by zero errors
that's alright - i'm using 4.0.6 and the suppression works thnx again -Original Message- From: Lars Torben Wilson [mailto:[EMAIL PROTECTED]] Sent: Friday, February 01, 2002 10:33 AM To: Christopher William Wesley Cc: [EMAIL PROTECTED]; Martin Towell Subject: Re: [PHP] suppressing division by zero errors On Thu, 2002-01-31 at 15:16, Christopher William Wesley wrote: You really need to do some error checking on the denominator. $num = 5; $den = 0; echo $den != 0 ? $num/$den : 0; A number divided by zero isn't defined, so you have to circumvent the situation by making sure it never happens. Actually, the result of a divide-by-zero will be boolean false in PHP 4. Though in older (4.0.3pl1, to be precise) versions, the warning doesn't seem to be suppressable. Hm. Torben ~Chris /\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden On Fri, 1 Feb 2002, Martin Towell wrote: Is there a way to suppress division by zero errors? echo 5/0; // this give a warning - obviously!! @echo 5/0; // this gives a parse error echo @5/0; // this still comes up with a warning unless I turn error_reporting off before and turn it back on afterwards, but I don't want to do that unless I REALLY have to Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]