Open In App

PHP | Types of Errors

Last Updated : 24 Aug, 2018
Like Article

Error is the fault or mistake in a program. It can be several types. Error can occur due to wrong syntax or wrong logic. It is a type of mistakes or condition of having incorrect knowledge of the code.

There are various types of errors in PHP but it contains basically four main type of errors.

  1. Parse error or Syntax Error: It is the type of error done by the programmer in the source code of the program. The syntax error is caught by the compiler. After fixing the syntax error the compiler compile the code and execute it. Parse errors can be caused dues to unclosed quotes, missing or Extra parentheses, Unclosed braces, Missing semicolon etc

    $x = "geeks";
    y = "Computer science";
    echo $x;
    echo $y;



    PHP Parse error:  syntax error, unexpected '=' 
    in /home/18cb2875ac563160a6120819bab084c8.php on line 3

    Explanation: In above program, $ sign is missing in line 3 so it gives an error message.

  2. Fatal Error: It is the type of error where PHP compiler understand the PHP code but it recognizes an undeclared function. This means that function is called without the definition of function.

    function add($x, $y)
        $sum = $x + $y;
        echo "sum = " . $sum;
    $x = 0;
    $y = 20;
    add($x, $y);
    diff($x, $y);



    PHP Fatal error:  Uncaught Error: 
    Call to undefined function diff() 
    in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php:12
    Stack trace:
    #0 {main}
      thrown in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php on line 12

    Explanation : In line 12, function is called but the definition of function is not available. So it gives error.

  3. Warning Errors : The main reason of warning errors are including a missing file. This means that the PHP function call the missing file.

    $x = "GeeksforGeeks";
    include ("gfg.php");
    echo $x . "Computer science portal";



    PHP Warning:  include(gfg.php): failed to 
    open stream: No such file or directory in 
    /home/aed0ed3b35fece41022f332aba5c9b45.php on line 5
    PHP Warning:  include(): Failed opening 'gfg.php'
     for inclusion (include_path='.:/usr/share/php') in 
    /home/aed0ed3b35fece41022f332aba5c9b45.php on line 5

    Explanation: This program call an undefined file gfg.php which are not available. So it produces error.

  4. Notice Error: It is similar to warning error. It means that the program contains something wrong but it allows the execution of script.

    $x = "GeeksforGeeks";
    echo $x;
    echo $geeks;



    PHP Notice:  Undefined variable: geeks in 
    /home/84c47fe936e1068b69fb834508d59689.php on line 5



    Explanation: This program use undeclared variable $geeks so it gives error message.

PHP error constants and their description :

  • E_ERROR : A fatal error that causes script termination
  • E_WARNING : Run-time warning that does not cause script termination
  • E_PARSE : Compile time parse error.
  • E_NOTICE : Run time notice caused due to error in code
  • E_CORE_ERROR : Fatal errors that occur during PHP’s initial startup (installation)
  • E_CORE_WARNING : Warnings that occur during PHP’s initial startup
  • E_COMPILE_ERROR : Fatal compile-time errors indication problem with script.
  • E_USER_ERROR : User-generated error message.
  • E_USER_WARNING : User-generated warning message.
  • E_USER_NOTICE : User-generated notice message.
  • E_STRICT : Run-time notices.
  • E_RECOVERABLE_ERROR : Catchable fatal error indicating a dangerous error
  • E_DEPRECATED : Run-time notices.

Similar Reads

Generating Errors using HTTP-errors module in Node.js
HTTP-errors module is used for generating errors for Node.js applications. It is very easy to use. We can use it with the express, Koa, etc. applications. We will implement this module in an express application. Installation and Setup: First, initialize the application with the package.json file with the following command: npm init Then, install th
2 min read
How to log errors and warnings into a file in php?
In PHP, errors and warnings can be logged into a file by using a php script and changing configuration of php.ini file. Two such approaches are mentioned below: Approach 1: The error_log() function can be used to send error messages to a given file. First argument to the function is the error message to be sent. Second argument tells where to send/
2 min read
How do I get PHP errors to display?
There are four ways to display errors in PHP which are listed below: error_reporting: It does not display the E-STRICT, E-NOTICE and E_DEPRECATED level errors and display all the other level errors.display_errors: Its default value is "off". Set it to "on".log_errors: It's default value is "on" which indicates whether or not error logging should be
2 min read
Exceptions Vs Errors in PHP
Error: An Error is an unexpected program result, which can not be handled by the program itself. That can be solved by using the issue in the code manually. An Error can be an infinite loop that can not be handled by the program itself so you have to manually repair that issue. There is an easy procedure to handle error i.e. using die() function. S
2 min read
How to show All Errors in PHP ?
We can show all errors in PHP using the error_reporting() function. It sets the error_reporting directive at runtime according to the level provided. If no level is provided, it will return the current error reporting level. error_reporting(E_ALL) level represents all errors, warnings, notices, etc. PHP Code: If the level is set to zero, no error i
3 min read
How to Handle errors in PHP?
Handling errors in PHP involves various techniques and constructs to detect, report, and manage errors or exceptions that occur during script execution. Table of Content Error Reporting LevelError Loggingtry-catch Blocks (Exceptions)Custom Error HandlersError Reporting Level:Controls the level of error messages displayed or logged in PHP scripts. /
1 min read
How to pass express errors message to Angular view ?
There are mainly two parts of a web application, one is front-end and another is the backend. We will start with the backend first. The express catches all errors that occur while running route handlers and middleware. We have to just send them properly to the frontend for user knowledge. Express catches and processes errors that occur both synchro
4 min read
Catching multiple async errors
In this article, we will try to understand how we may catch multiple asynchronous (abbreviated as "async") errors in JavaScript with the help of certain coding examples. Let us first understand how we may create an async function (along with the usage of await keyword) with the help of the following illustrated syntaxes (the first one is through no
3 min read
How to catch all JavaScript errors and send them to server ?
Today there are a large number of Web APIs available. One of which is GlobalEventHandlers, an OnErrorEventHandler to be called when the error is raised. The onerror property of the GlobalEventHandlers is an EventHandler that processes error events. This is great for catching exceptions that never occur while testing. The different error events are
2 min read
How to handle errors in node.js ?
Node.js is a JavaScript extension used for server-side scripting. Error handling is a mandatory step in application development. A Node.js developer may work with both synchronous and asynchronous functions simultaneously. Handling errors in asynchronous functions is important because their behavior may vary, unlike synchronous functions. While try
4 min read
Article Tags :