Về cơ bản, một lỗi là một sai lầm trong một chương trình có thể được gây ra bằng cách viết cú pháp không chính xác hoặc mã không chính xác. Một thông báo lỗi được hiển thị trên trình duyệt của bạn chứa tên tệp cùng với vị trí, một thông báo mô tả lỗi và số dòng trong đó xảy ra lỗi.
Thường có các loại lỗi khác nhau. Trong PHP, chủ yếu là bốn loại lỗi được xem xét:
- Lỗi cú pháp hoặc lỗi phân tích cú pháp
- Lỗi nghiêm trọng
- Lỗi cảnh báo
- Thông báo lỗi
Chúng tôi sẽ thảo luận chi tiết về tất cả các lỗi này với các ví dụ:
Lỗi cú pháp hoặc lỗi phân tích cú pháp
Lỗi nghiêm trọngParse error. Compiler is used to catch the syntax error at compile time.
Lỗi cảnh báo
Thông báo lỗi
Chúng tôi sẽ thảo luận chi tiết về tất cả các lỗi này với các ví dụ:
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Parse error: syntax error, unexpected 'echo' [T_ECHO], expecting ',' or ';' in C:\xampp\htdocs\program\fatalerror.php on line 5
Lưu ý: Lỗi cú pháp dừng thực thi mã. In this above example, a semicolon [;] was missing in line 5. So, it generated a parse error and displayed an error message on browser as given in the output.
Những lỗi này có thể xảy ra do những lý do phổ biến này như trích dẫn không được giải thích, thiếu dấu chấm, dấu ngoặc đơn hoặc thiếu hoặc dấu ngoặc không được giải thích và nhiều hơn nữa. Trong khi biên dịch chương trình, lỗi cú pháp có thể được trình biên dịch bắt. Nó cung cấp một lỗi phân tích cú pháp hoặc thông báo lỗi cú pháp.
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
Lưu ý: Lỗi cú pháp dừng thực thi mã. In this above example, dollar [$] symbol was missing in line 5. So, it generated a parse error and displayed an error message on browser as given in the output.
Lỗi nghiêm trọng
Lỗi cảnh báo
Thông báo lỗi
Chúng tôi sẽ thảo luận chi tiết về tất cả các lỗi này với các ví dụ:
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.catch_fatal_error[]. Therefore, it generates a fatal error and print an error message on the browser as given below:
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
Lỗi cảnh báo
Thông báo lỗi
Chúng tôi sẽ thảo luận chi tiết về tất cả các lỗi này với các ví dụ:
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Warning Error: Warning: include[jtp.php]: failed to open stream: No such file or directory in C:\xampp\htdocs\program\fatalerror.php on line 7 Warning: include[]: Failed opening 'jtp.php' for inclusion [include_path='C:\xampp\php\PEAR'] in C:\xampp\htdocs\program\fatalerror.php on line 7
Lưu ý: Lỗi cú pháp dừng thực thi mã. In this example, we tried to include a file in our program, which does not exist. So, it generated a warning and displayed an error message.
Thông báo lỗi
Chúng tôi sẽ thảo luận chi tiết về tất cả các lỗi này với các ví dụ:For example - access to undefined variable.
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Lưu ý: Lỗi cú pháp dừng thực thi mã.
Lỗi cú pháp là một sai lầm trong cú pháp của mã nguồn, có thể được thực hiện bởi các lập trình viên do sự thiếu quan tâm hoặc kiến thức của họ. Nó còn được gọi là lỗi phân tích cú pháp. Trình biên dịch được sử dụng để bắt lỗi cú pháp tại thời điểm biên dịch.
Airtel Notice: Undefined variable: automobile in C:\xampp\htdocs\program\fatalerror.php on line 6
Lưu ý: Lỗi cú pháp dừng thực thi mã. In this above example, we were trying to use a variable $automobile, which was not defined. Therefore, it generated a notice "Undefined variable" and continued the execution of the program.
Hàm lỗi PHP là gì?
Các hàm lỗi được sử dụng để xử lý lỗi và ghi nhật ký. Các hàm lỗi cho phép chúng tôi xác định các quy tắc xử lý lỗi của chính riêng và sửa đổi cách thức có thể ghi lại lỗi. Các chức năng ghi nhật ký cho phép chúng tôi gửi tin nhắn trực tiếp đến các máy, email hoặc nhật ký hệ thống khác.
Trình xử lý lỗi và lỗi trong PHP là gì?
Hàm lỗi PHP là gì?
Các hàm lỗi được sử dụng để xử lý lỗi và ghi nhật ký. Các hàm lỗi cho phép chúng tôi xác định các quy tắc xử lý lỗi của chính riêng và sửa đổi cách thức có thể ghi lại lỗi. Các chức năng ghi nhật ký cho phép chúng tôi gửi tin nhắn trực tiếp đến các máy, email hoặc nhật ký hệ thống khác.
Trình xử lý lỗi và lỗi trong PHP là gì?
Xử lý lỗi là quá trình bắt các lỗi được đưa ra bởi chương trình của bạn và sau đó thực hiện hành động thích hợp. Nếu bạn sẽ xử lý các lỗi đúng thì nó có thể dẫn đến nhiều hậu quả không lường trước được. Nó rất đơn giản trong PHP để xử lý một lỗi.
Xem thảo luận basically four main type of errors.
- Cải thiện bài viết 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
Example:Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
0Lưu bài viết
Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
5Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
6Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4PHP 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
7PHP 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
8PHP 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
9PHP Parse error: syntax error, unexpected '=' in /home/18cb2875ac563160a6120819bab084c8.php on line 3
5Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
8Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Airtel Notice: Undefined variable: automobile in C:\xampp\htdocs\program\fatalerror.php on line 6
3PHP 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
4Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
4Error:
PHP Parse error: syntax error, unexpected '=' in /home/18cb2875ac563160a6120819bab084c8.php on line 3
Giải thích: Chương trình này gọi một tệp không xác định gfg.php không có sẵn. Vì vậy, nó tạo ra lỗi. In above program, $ sign is missing in line 3 so it gives an error message.
- Lỗi thông báo: Nó tương tự như lỗi cảnh báo. Điều đó có nghĩa là chương trình chứa sai điều gì đó nhưng nó cho phép thực hiện script.example: 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.
Example:Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
0Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
8Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Warning Error: Warning: include[jtp.php]: failed to open stream: No such file or directory in C:\xampp\htdocs\program\fatalerror.php on line 7 Warning: include[]: Failed opening 'jtp.php' for inclusion [include_path='C:\xampp\php\PEAR'] in C:\xampp\htdocs\program\fatalerror.php on line 7
2Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
8PHP Notice: Undefined variable: geeks in /home/84c47fe936e1068b69fb834508d59689.php on line 5
6Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Giải thích: Chương trình này sử dụng biến không được khai báo $ Geek để nó đưa ra thông báo lỗi.
Airtel Notice: Undefined variable: automobile in C:\xampp\htdocs\program\fatalerror.php on line 6
6Hằng số lỗi PHP và mô tả của chúng:
E_error: một lỗi gây tử vong gây ra kết thúc tập lệnh
E_Warning: Cảnh báo thời gian chạy không gây ra kết thúc tập lệnh
PHP Parse error: syntax error, unexpected '=' in /home/18cb2875ac563160a6120819bab084c8.php on line 3
6Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
9Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
2PHP Parse error: syntax error, unexpected '=' in /home/18cb2875ac563160a6120819bab084c8.php on line 3
5Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
4Error:
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
E_Parse: Biên dịch lỗi phân tích thời gian. In line 12, function is called but the definition of function is not available. So it gives error.
- Lỗi cảnh báo: Lý do chính của lỗi cảnh báo là bao gồm một tệp bị thiếu. Điều này có nghĩa là chức năng PHP gọi tệp bị thiếu.example: The main reason of warning errors are including a missing file. This means that the PHP function call the missing file.
Example: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
2Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
2PHP 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
5Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4PHP 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
7PHP 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
8PHP 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
9PHP Parse error: syntax error, unexpected '=' in /home/18cb2875ac563160a6120819bab084c8.php on line 3
5Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
8Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Airtel Notice: Undefined variable: automobile in C:\xampp\htdocs\program\fatalerror.php on line 6
3PHP 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
4Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
4Error:
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
Giải thích: Chương trình này gọi một tệp không xác định gfg.php không có sẵn. Vì vậy, nó tạo ra lỗi. This program call an undefined file gfg.php which are not available. So it produces error.
- Lỗi thông báo: Nó tương tự như lỗi cảnh báo. Điều đó có nghĩa là chương trình chứa sai điều gì đó nhưng nó cho phép thực hiện script.example: It is similar to warning error. It means that the program contains something wrong but it allows the execution of
script.
Example: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
2Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
2PHP 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
5Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
8Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
1Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
8PHP Notice: Undefined variable: geeks in /home/84c47fe936e1068b69fb834508d59689.php on line 5
6Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\program\fatalerror.php on line 5
4Fatal error: Uncaught Error: Call to undefined function catch_fatal_error[] in C:\xampp\htdocs\program\fatalerror.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\program\fatalerror.php on line 13
4Error:
PHP Notice: Undefined variable: geeks in /home/84c47fe936e1068b69fb834508d59689.php on line 5
Output:
GeeksforGeeks
Giải thích: Chương trình này sử dụng biến không được khai báo $ Geek để nó đưa ra thông báo lỗi. This program use undeclared variable $geeks so it gives error message.
Hằng số lỗi PHP và mô tả của chúng:
- E_error: một lỗi gây tử vong gây ra kết thúc tập lệnh A fatal error that causes script termination
- E_Warning: Cảnh báo thời gian chạy không gây ra kết thúc tập lệnh Run-time warning that does not cause script termination
- E_Parse: Biên dịch lỗi phân tích thời gian. Compile time parse error.
- E_notice: Chạy thông báo thời gian gây ra do lỗi trong mãRun time notice caused due to error in code
- E_CORE_ERROR: Lỗi nghiêm trọng xảy ra trong quá trình khởi động ban đầu của PHP [Cài đặt]Fatal errors that occur during PHP’s initial startup [installation]
- E_core_warning: cảnh báo xảy ra trong khi khởi động ban đầu của PHPWarnings that occur during PHP’s initial startup
- E_Compile_error: Lỗi thời gian biên dịch gây tử vong Vấn đề chỉ định với tập lệnh. Fatal compile-time errors indication problem with script.
- E_USER_ERROR: Thông báo lỗi do người dùng tạo. User-generated error message.
- E_USER_WARNING: Thông báo cảnh báo do người dùng tạo. User-generated warning message.
- E_USER_NOTICE: Thông báo thông báo do người dùng tạo. User-generated notice message.
- E_Strict: Thông báo thời gian chạy. Run-time notices.
- E_RECOVERABLE_ERROR: Lỗi nghiêm trọng có thể bắt được cho thấy lỗi nguy hiểm Catchable fatal error indicating a dangerous error
- E_Deprecated: Thông báo thời gian chạy. Run-time notices.