Home  >  Article  >  Backend Development  >  What are the types of PHP errors?

What are the types of PHP errors?

藏色散人
藏色散人Original
2019-01-15 17:02:074392browse

What are the types of PHP errors?

Error Error is a fault or mistake in the program. It can be of several types. Errors may occur due to syntax errors or logical errors. This is a condition of error or incorrect knowledge of the code.

What are the types of PHP errors?

#There are various types of errors in PHP, but it basically consists of four major types of errors.

1. Parsing error or syntax error: This is the type of error done by the programmer in the source code of the program. Syntax errors are caught by the compiler. After fixing the syntax errors, the compiler compiles the code and executes it. Parsing errors may result from undisclosed quotes, missing or extra parentheses, unclosed braces, missing semicolons, and more

Example:

<?php 
$x = "geeks"; 
y = "Computer science"; 
echo $x; 
echo $y; 
?>

ErrorError:

PHP Parse error:  syntax error, unexpected &#39;=&#39; 
in /home/18cb2875ac563160a6120819bab084c8.php on line 3

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

2. Fatal Error Fatal Error: This is the type of error where the PHP compiler understands the PHP code but it recognizes an undeclared function. This means calling a function without a function definition.

Example:

<?php 
  
function add($x, $y) 
{ 
    $sum = $x + $y; 
    echo "sum = " . $sum; 
} 
$x = 0; 
$y = 20; 
add($x, $y); 
  
diff($x, $y); 
?>

ErrorError:

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, the function is called, but the definition of the function is not available. So it gives error.

3. Warning Errors Warning Errors : The main causes of warning errors include missing files. This means the PHP function call is missing from the file.

Example:

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

ErrorError:

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 &#39;gfg.php&#39;
 for inclusion (include_path=&#39;.:/usr/share/php&#39;) in 
/home/aed0ed3b35fece41022f332aba5c9b45.php on line 5

Explanation: The program calls an undefined file gfg.php that is not available. So it will generate error.

4. Notice Error: It is similar to a warning error. This means that the program contains an error but it allows script execution.

Example:

<?php  
  
$x = "GeeksforGeeks"; 
  
echo $x; 
  
echo $geeks; 
?>

ErrorError:

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

Output:

GeeksforGeeks

Explanation: This program uses the undeclared variable $geeks, so it gives error message.

PHP error constants and their descriptions:

E_ERROR:导致脚本终止的致命错误
E_WARNING:不会导致脚本终止的运行时警告
E_PARSE:编译时间解析错误。
E_NOTICE:由于代码中的错误导致的运行时通知
E_CORE_ERROR: PHP初始启动(安装)期间发生的致命错误
E_CORE_WARNING: PHP初始启动期间发生的警告
E_COMPILE_ERROR:脚本的致命编译时错误指示问题。
E_USER_ERROR:用户生成的错误消息。
E_USER_WARNING:用户生成的警告消息。
E_USER_NOTICE:用户生成的通知消息。
E_STRICT:运行时通知。
E_RECOVERABLE_ERROR:可捕获的致命错误,表示存在危险错误
E_DEPRECATED:运行时通知。

The above is the detailed content of What are the types of PHP errors?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn