Loading...
PHP

Types of Errors In PHP

In php there are 4 different types of errors.
1. Notice
2. Warning
3. Fatal Error
4. Parse Error

  1. Notice: Notice is small information to the end user do not stop execution of script. If your trying to access and undefined variables output is notices. By default we can see notice message and browser because in php.ini one configuration setting a available to display all file errors that is error-reporting. Default value is E_ALL and ~E_NOTICE means display all errors except notice message. By removing E_NOTICE we can display notice on the browser or use error_reporting, E_ALL function and web page where we want the errors.
    <?php
    error_reporting(E_ALL);
    $x=100;
    echo $x;
    echo $y;  //notice
    echo “hi”;
    ?>
  2. Warning: Warning also same as notice doesn’t stop execution of script. If we trying to access undefined constant output is warning. Constant is same as variable using to store values but constant value is fixed means we can’t change the values what we assigned first time. In PHP we can declare constants using defined function and we can access constants using constant function.
    <?php
    define (“Sno”,100);
    echo constant(“Sno”);
    echo constant(“un”)//warning
    echo “Next”;
    ?>
  3. Fatal Error: Fatal error stop the execution of script from the line where error is occurred. If we are trying to access undefined function output is Fatal error.
    <?php
    echo “HI”;
    defined(“Sno”,100); //Fatal
    echo “Hello”;
    ?>
  4. Parse Error: If there is any syntax mistake in the script output is parse error it stop the execution of complete script.
    <?php
    echo “line 1”;
    echo “line 2”;//parse
    echo “line 3”;
    ?>
Leave a Reply

Your email address will not be published. Required fields are marked *