Newbie
Newbie

Reputation: 2825

how to disable the browser to give warning in php?

When some thing is divided by 0, the webpage will appear a line of waring like this" Warning: Division by zero in C:\xampp\htdocs\XXXX.php on line 109". How can I solve this problem.

Thanks

Upvotes: 0

Views: 3185

Answers (4)

Jan Vorcak
Jan Vorcak

Reputation: 20009

first of all, you have to avoid these errors, using conditions or exceptions if it's not possible you can disable error reporting

// Turn off all error reporting
error_reporting(0);

source - error_reporting

Upvotes: 2

Glory Raj
Glory Raj

Reputation: 17701

you can use error_reporting functions....

   <?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

Upvotes: 3

JJJ
JJJ

Reputation: 33163

Make sure that you don't divide by zero.

if( $divisor != 0 ) {
    $result = $number / $divisor;
}
else {
    $result = 0; // or print an error or whatever
}

Upvotes: 4

Incognito
Incognito

Reputation: 20765

You find the bug, then you fix it.

You don't suppress errors.

Upvotes: 5

Related Questions