Warning: division by zero definition

Discussion in 'PHP' started by egdcltd, Apr 14, 2008.

  1. #1
    Could someone point me to an explanation of the Warning: division by zero error please? I thought I knew what it meant, but I'm not sure now.
     
    egdcltd, Apr 14, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    It simply means you are trying to divide by zero, which is mathematically impossible (how many 0's can you fit in 1, for example). Some say infinity, but its more undefined, hence the error.

    See this link for the specifics: http://mathforum.org/dr.math/faq/faq.divideby0.html

    Jay
     
    jayshah, Apr 14, 2008 IP
  3. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's what I thought it was. Would you get the same error if the variable was an empty value, instead of 0? eg '' instead of '0'
     
    egdcltd, Apr 14, 2008 IP
  4. wisdomtool

    wisdomtool Moderator Staff

    Messages:
    15,826
    Likes Received:
    1,367
    Best Answers:
    1
    Trophy Points:
    455
    #4
    Division by zero is mathematically undefined, so if your program has such an error you will need to check the variables and put in some constraints.
     
    wisdomtool, Apr 14, 2008 IP
  5. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Yes:

    
    <?php
    $four = 4;
    $empty = '';
    
    echo $four / $empty;
    ?>
    
    PHP:
    [b]Warning:[/b] Division by zero in /divzero.php on line 5
    Code (markup):
    PHP Automatically converts string to integers ('' becomes 0) when applying mathematical operations.

    Jay
     
    jayshah, Apr 14, 2008 IP
  6. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It was an empty value causing the problem. Tracked down where it was coming from, and fixed it. Thanks.
     
    egdcltd, Apr 18, 2008 IP