Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    warning messages division by zero

    morning all,

    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?

    cheers all
    Sir P

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    How about using the error_reporting function at the beginning of your script:
    PHP Code:
    error_reporting(0); 
    Alternatively, the @-operator might suffice for preventing warning message for the single statement:
    PHP Code:
    @$a 5/0// no warning displayed 

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    If you get division by zero errors then there is something wrong in the code as a whole.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    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?

    Cheers,
    P

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,081
    Thanks
    11
    Thanked 99 Times in 97 Posts
    better off to check first..
    PHP Code:
    <?php
    $blah
    =$num;
    if(
    $divisor!==0){
      
    $blah=$num/$divisor;
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    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?

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Is getting wrong results not a problem for you?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,081
    Thanks
    11
    Thanked 99 Times in 97 Posts
    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.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Thanks firepages.

    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

  • #10
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •