Hướng dẫn how can i get the last error in php? - Làm thế nào tôi có thể nhận được lỗi cuối cùng trong php?

(Php 5> = 5.2.0, Php 7, Php 8)

ERROR_GET_LAST - Nhận lỗi xảy ra cuối cùngGet the last occurred error

Sự mô tả

ERROR_GET_LAST ():? Mảng(): ?array

Thông số

Chức năng này không có tham số.

Trả về giá trị

Trả về một mảng kết hợp mô tả lỗi cuối cùng với các khóa "Loại", "Tin nhắn", "Tệp" và "Line". Nếu lỗi đã được gây ra bởi hàm nội bộ PHP thì "thông báo" bắt đầu bằng tên của nó. Trả về null nếu chưa có lỗi.null if there hasn't been an error yet.

Ví dụ

Ví dụ #1 một ví dụ về error_get_last ()error_get_last() example

<?php
echo $a;
print_r(error_get_last());
?>

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

Array
(
    [type] => 8
    [message] => Undefined variable: a
    [file] => C:\WWW\index.php
    [line] => 2
)

Xem thêm

  • Hằng số lỗi
  • Biến $ PHP_ERRORMSG
  • ERROR_CLEAR_LAST () - Xóa lỗi gần đây nhất
  • Chỉ thị display_errors
  • Chỉ thị html_errors
  • Chỉ thị xmlrpc_errors

DMGX DOT Michael tại Gmail Dot Com ¶

11 năm trước

If an error handler (see set_error_handler ) successfully handles an error then that error will not be reported by this function.

Nicolas Dot Grekas+PHP tại Gmail Dot Com ¶

8 năm trước

[Editor's note: as of PHP 7.0.0 there is error_clear_last() to clear the most recent error.]

To clear error_get_last(), or put it in a well defined state, you should use the code below. It works even when a custom error handler has been set.

<?php // var_dump or anything else, as this will never be called because of the 0
set_error_handler('var_dump', 0);
@
$undef_var;
restore_error_handler(); // error_get_last() is now in a well known state:
// Undefined variable: undef_var
... // Do something $e = error_get_last();

null0

null1

Skrol29 ¶

12 năm trước

null2

null3

null4

null5

null6

Michael tại getprink dot com ¶

13 năm trước

null7

null8

null9

<?php
echo $a;
print_r(error_get_last());
?>
0

<?php
echo $a;
print_r(error_get_last());
?>
1

Vike2000 tại miền Google Mail ¶

9 năm trước

<?php
echo $a;
print_r(error_get_last());
?>
2

<?php
echo $a;
print_r(error_get_last());
?>
3

null6

Brad ¶

14 năm trước

<?php
echo $a;
print_r(error_get_last());
?>
5

<?php
echo $a;
print_r(error_get_last());
?>
6

<?php
echo $a;
print_r(error_get_last());
?>
7

<?php
echo $a;
print_r(error_get_last());
?>
8

Iant tại clickwt dot com ¶

12 năm trước

<?php
echo $a;
print_r(error_get_last());
?>
9

null9

<?php
echo $a;
print_r(error_get_last());
?>
0

display_errors2

Brad ¶

14 năm trước

display_errors3

Iant tại clickwt dot com ¶

11 năm trước

display_errors4

If an error handler (see set_error_handler ) successfully handles an error then that error will not be reported by this function.

Nicolas Dot Grekas+PHP tại Gmail Dot Com ¶

display_errors5

display_errors6

display_errors7

display_errors8

8 năm trước

12 năm trước

display_errors9

html_errors0

null6

Michael tại getprink dot com ¶

14 năm trước

html_errors2

Iant tại clickwt dot com ¶

13 năm trước

html_errors3

html_errors4

null6

Làm thế nào tôi có thể nhận được lỗi trong 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.

Chức năng nào nhận được thông tin về lỗi cuối cùng xảy ra?

Hàm error_get_last () trả về lỗi cuối cùng xảy ra (dưới dạng mảng kết hợp). Mảng liên kết chứa bốn khóa: [Loại] - Mô tả loại lỗi.error_get_last() function returns the last error that occurred (as an associative array). The associative array contains four keys: [type] - Describes the error type.

ERR trong PHP là gì?

Lỗi PHP xảy ra khi có điều gì đó không ổn trong mã PHP.Lỗi có thể đơn giản như một dấu chấm phẩy bị thiếu hoặc phức tạp như gọi một biến không chính xác.Để giải quyết hiệu quả vấn đề PHP trong tập lệnh, bạn phải hiểu loại vấn đề nào đang xảy ra.. The error can be as simple as a missing semicolon, or as complex as calling an incorrect variable. To efficiently resolve a PHP issue in a script, you must understand what kind of problem is occurring.

Các lỗi phổ biến nhất trong PHP là gì?

10 lỗi PHP hàng đầu từ hơn 1.000 dự án (và cách tránh chúng)..
Lỗi phân tích phân tích PHP: Lỗi cú pháp, kết thúc không mong muốn của tệp ..
E_Warning: Đối số không hợp lệ được cung cấp cho foreach ().
QueryException: SQLSTATE [23000]: Vi phạm ràng buộc toàn vẹn ..
QueryException: SQLSTATE [42S22]: Không tìm thấy cột:.