Hướng dẫn php check error reporting level - kiểm tra php mức báo cáo lỗi
Trang chủ / Nhận và Sửa đổi mức báo cáo lỗi trong PHPGet and modify the error reporting level in PHP Show Hàm Error_Reporting () của PHP cho phép tập lệnh kiểm tra mức báo cáo lỗi hiện tại là gì và/hoặc sửa đổi nó. Tôi thường không khuyên bạn nên thay đổi cấp độ báo cáo lỗi theo chương trình, nhưng có thể có lúc cần thiết. Điều tuyệt vời là dễ dàng có thể có được cấp độ hiện tại, thay đổi nó, và sau đó đặt nó trở lại những gì trước đây. Nhận mức báo cáo hiện tạiĐể có được mức báo cáo Curent, chỉ cần gọi hàm ERROR_REPORTING () mà không cần truyền bất kỳ tham số nào, như vậy: $current_error_reporting = error_reporting(); Điều này sẽ trả về một giá trị số nguyên. Ví dụ, bạn có thể thấy nếu E_Notice được đặt ở cấp báo cáo lỗi như vậy: if($current_error_reporting & E_NOTICE) { // do something } Để thay đổi mức báo cáo lỗi thành một cái gì đó khác nhau, hãy chuyển cấp độ mới làm tham số. Trả về giá trị từ lệnh gọi hàm là mức báo cáo lỗi cũ. Ví dụ sau đây thay đổi mức báo cáo lỗi cho mọi thứ nhưng thông báo và lưu trữ cấp độ cũ trong một biến.old error reporting level. The following example changes the error reporting level to everything but notices and stores the old level in a variable. $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE); Mức báo cáo lỗi cũ sau đó có thể được khôi phục sau: error_reporting($old_error_reporting); Xóa thông báo khỏi cấp báo cáo hiện tạiVí dụ cuối cùng này loại bỏ e_notice khỏi cấp độ báo cáo hiện tại, chạy một số mã khác và sau đó khôi phục lại cấp độ cũ. // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting); Trên đây có thể được kiểm tra bằng mã sau. Nó đặt mức báo cáo lỗi thành e_all khi bắt đầu để chúng tôi có thể chắc chắn khi kiểm tra giá trị ban đầu là gì: error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n"; Đầu ra này 6143 6135 6143 được mong đợi: 6143 là e_all và 6135 là e_all mà không có e_notice. (Php 4, Php 5, Php 7, Php 8) Error_Reporting - Các bộ lỗi PHP được báo cáo — Sets which PHP errors are reported Sự mô tảError_Reporting (? int Thông sốerror_level Mức độ lỗi mới. Nó có một hoặc một hằng số được đặt tên. Sử dụng các hằng số được đặt tên được khuyến khích mạnh mẽ để đảm bảo khả năng tương thích cho các phiên bản trong tương lai. Khi các mức lỗi được thêm vào, phạm vi số nguyên tăng, do đó các mức lỗi dựa trên số nguyên cũ sẽ không luôn luôn hoạt động như mong đợi. Các hằng số mức lỗi có sẵn và ý nghĩa thực tế của các mức lỗi này được mô tả trong các hằng số được xác định trước. Trả về giá trị Trả về mức ERROR_REPORTING cũ hoặc mức hiện tại nếu không có tham số Thay đổi
Ví dụVí dụ #1 Error_Reporting () Ví dụerror_reporting() examples if($current_error_reporting & E_NOTICE) { // do something }2 Ghi chúMẹo Truyền trong giá trị if($current_error_reporting & E_NOTICE) { // do something }3 sẽ hiển thị mọi lỗi có thể xảy ra, ngay cả khi các cấp độ và hằng số mới được thêm vào các phiên bản PHP trong tương lai. Hành vi tương đương với việc vượt qua hằng số if($current_error_reporting & E_NOTICE) { // do something }4. if($current_error_reporting & E_NOTICE) { // do something }4 constant. Xem thêm
Thông tin tại Hephoz Dot de ¶ ¶ 14 năm trước if($current_error_reporting & E_NOTICE) { // do something }5 if($current_error_reporting & E_NOTICE) { // do something }6 if($current_error_reporting & E_NOTICE) { // do something }7 if($current_error_reporting & E_NOTICE) { // do something }8 if($current_error_reporting & E_NOTICE) { // do something }9 jcastromail tại yahoo dot es ¶ ¶ 1 năm trước $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);0 $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);1 $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);2 $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);3 $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);4 Dave tại Davidhbrown dot chúng tôi ¶ ¶ 16 năm trước $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);5 $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);6 $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);7 if($current_error_reporting & E_NOTICE) { // do something }9 Piancastelli Fernando ¶ 17 năm trước $old_error_reporting = error_reporting(E_ALL ^ E_NOTICE);9 error_reporting($old_error_reporting);0 error_reporting($old_error_reporting);1 if($current_error_reporting & E_NOTICE) { // do something }9 Luisdev ¶ ¶ 4 năm trước error_reporting($old_error_reporting);3 error_reporting($old_error_reporting);4 error_reporting($old_error_reporting);5 error_reporting($old_error_reporting);6 error_reporting($old_error_reporting);7 if($current_error_reporting & E_NOTICE) { // do something }9 lhenry tại lhenry dot com ¶ 2 năm trước error_reporting($old_error_reporting);9 // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);0 // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);1 // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);2 if($current_error_reporting & E_NOTICE) { // do something }9 Adam tại Adamhahn dot com ¶ 5 năm trước // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);4 // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);5 if($current_error_reporting & E_NOTICE) { // do something }9 Keithm tại Aoeex dot com ¶ ¶ 12 năm trước // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);7 // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);8 // remove E_NOTICE from error reporting and store previous value $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); // run some other code // ... code ... // restore old error reporting level error_reporting($old_error_reporting);9 error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";0 error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";1 if($current_error_reporting & E_NOTICE) { // do something }9 Qeremy! gmail ¶ ¶ 7 năm trước error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";3 error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";4 if($current_error_reporting & E_NOTICE) { // do something }9 Phát ban ¶ ¶ 7 năm trước error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";6 error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";7 if($current_error_reporting & E_NOTICE) { // do something }9 Phát ban ¶ ¶ 4 năm trước error_reporting(E_ALL); echo error_reporting(), "n"; $old_error_reporting = error_reporting(error_reporting() ^ E_NOTICE); echo error_reporting(), "n"; error_reporting($old_error_reporting); echo error_reporting(), "n";9 lhenry tại lhenry dot com ¶ 2 năm trước 6143 6135 61430 6143 6135 61431 if($current_error_reporting & E_NOTICE) { // do something }9 Adam tại Adamhahn dot com ¶ 14 năm trước 6143 6135 61433 6143 6135 61434 6143 6135 61435 6143 6135 61436 if($current_error_reporting & E_NOTICE) { // do something }9 jcastromail tại yahoo dot es ¶ ¶ 1 năm trước 6143 6135 61438 6143 6135 61439
if($current_error_reporting & E_NOTICE) { // do something }9 Dave tại Davidhbrown dot chúng tôi ¶ ¶ 16 năm trước
if($current_error_reporting & E_NOTICE) { // do something }9 Piancastelli Fernando ¶ 5 năm trước
Keithm tại Aoeex dot com ¶ ¶ 17 năm trước
Luisdev ¶ ¶ 17 năm trước
if($current_error_reporting & E_NOTICE) { // do something }9 Luisdev ¶ ¶ 4 năm trước
error_level 5lhenry tại lhenry dot com ¶ 2 năm trước
if($current_error_reporting & E_NOTICE) { // do something }9 Adam tại Adamhahn dot com ¶ 4 năm trước
if($current_error_reporting & E_NOTICE) { // do something }00 if($current_error_reporting & E_NOTICE) { // do something }01 if($current_error_reporting & E_NOTICE) { // do something }9 lhenry tại lhenry dot com ¶ 2 năm trước if($current_error_reporting & E_NOTICE) { // do something }03 if($current_error_reporting & E_NOTICE) { // do something }04 if($current_error_reporting & E_NOTICE) { // do something }9 Adam tại Adamhahn dot com ¶ 5 năm trước if($current_error_reporting & E_NOTICE) { // do something }06 if($current_error_reporting & E_NOTICE) { // do something }07 if($current_error_reporting & E_NOTICE) { // do something }08 if($current_error_reporting & E_NOTICE) { // do something }9 Keithm tại Aoeex dot com ¶ ¶ 17 năm trước if($current_error_reporting & E_NOTICE) { // do something }10 if($current_error_reporting & E_NOTICE) { // do something }11 if($current_error_reporting & E_NOTICE) { // do something }12 if($current_error_reporting & E_NOTICE) { // do something }9 Luisdev ¶ ¶ 2 năm trước if($current_error_reporting & E_NOTICE) { // do something }14 Có bao nhiêu cấp độ báo cáo lỗi trong PHP?Có bao nhiêu mức độ lỗi trong PHP?Có 16 mức độ lỗi trong PHP 5. Các lỗi này đại diện cho danh mục và đôi khi mức độ nghiêm trọng của một lỗi trong PHP.16 error levels in PHP 5. These errors represent the category and sometimes severity of an error in PHP.
Làm cách nào để kiểm tra lỗi PHP?Cách nhanh nhất để hiển thị tất cả các lỗi và cảnh báo PHP là thêm các dòng này vào tệp mã PHP của bạn: ini_set ('display_errors', 1);ini_set ('display_startup_errors', 1);error_Reporting (e_all);Hàm ini_set sẽ cố gắng ghi đè cấu hình được tìm thấy trong PHP của bạn.Tệp INI.ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); The ini_set function will try to override the configuration found in your php. ini file.
Mức lỗi nào được sử dụng trong PHP?Lỗi PHP: 4 loại khác nhau (cảnh báo, phân tích, gây tử vong và lỗi thông báo)Warning, Parse, Fatal, and Notice Error)
Việc sử dụng hàm error_Reporting () trong PHP là gì?Hàm error_Reporting () chỉ định các lỗi nào được báo cáo.PHP có nhiều mức độ lỗi và sử dụng chức năng này đặt mức đó cho tập lệnh hiện tại.specifies which errors are reported. PHP has many levels of errors, and using this function sets that level for the current script. |