+

PHP Types of errors

PHP has various types of errors, but mostlycontains four major error types .
  • Parse error or a syntax error:This is a type of error made by the programmer in the source code of the program. The syntax error is caught by the compiler. After correcting the syntax error, the compiler compiles the code and executes it. Parsing errors can be caused by unclosed quotes, missing or extra parentheses, unclosed parentheses, missing semicolons, etc.
    Example : $x = "engineer" ; y = "Computer science" ; echo $x ; echo $y ; ?> Error:
    PHP Parse error: syntax error, unexpected `=` in /home/18cb2875ac563160a6120819bab084c8.php on line 3 
    Explanation:There is no $sign in the above program on line 3,therefore throws an error.
  • Fatal error:this is an error type where the PHP compiler understands PHP code but recognizes an undeclared function ... This means that the function is called without defining the function. 
    Example : function add ( $x , $y ) { $sum = $x + $y ; echo "sum =" . $sum ; } $x = 0; $y = 20; add ( $x , $y ); diff ( $x , $y ); ?> Error:
    PHP Fatal error: Uncaught Error: Call to undefined function diff() in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php:12 Stack trace: # 0 {main} thrown in /home/36db1ad4634ff7deb7f7347a4ac14d3a.php Explanation:On line 12, a function is called, but no function definition is available. So it gives an error.
  • Warning Errors . The root cause of warning errors is - missing file. This means that the PHP function is calling the missing file. 
    Example : $x = "GeeksforGeeks" ; include ( " gfg.php " ); echo $x . "Computer science portal" ; ?> Error:
    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 calls an undefined file gfg.php which not available. So it throws an error.
  • Notification error:This looks like an error warning. This means that something is wrong in the program, but it allows the script to be executed. 
    Example : $x = "GeeksforGeeks" ; echo $x ; echo $engineer ; ?> Error:
    PHP Notice: Undefined variable: engineer in /home/84c47fe936e1068b69fb834508d59689.php on line 5 
    Exit :
    GeeksforGeeks 
    Explanation:This program uses undeclared variable$engineer, so it gives an error message.
  • PHP error constants and their description:
    • E_ERROR:fatal error that causes the script to terminate
    • E_WARNING: runtime warning that does not cause the script to terminate
    • E_PARSE:compile-time parsing error.
    • E_NOTICE:runtime notification caused by a bug in code
    • E_CORE_ERROR:fatal errors that occur when PHP initially starts (install)
    • E_CORE_WARNING: Warnings, on initial PHP startup
    • E_COMPILE_ERROR:fatal error of compile time indication with script.
    • E_USER_ERROR:error message generated user.
    • E_USER_WARNING:custom alert.
    • E_USER_NOTICE:custom notice
    • E_STRICT:runtime notifications.
    • E_RECOVERABLE_ERROR:Recoverable fatal error indicating a dangerous error
    • E_DEPRECATED: runtime notifications.
    Get Solution for free from DataCamp guru