You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds an INI setting, 'fatal_error_backtraces', which users
can enable or disable to control whether or not PHP produces backtraces
for fatal errors.
It defaults to enabled, meaning that any non-recoverable error will now
have a backtrace associated with it. For example, a script timeout will
now look like:
Fatal error: Maximum execution time of 1 second exceeded in example.php on line 23
Stack trace:
#0 example.php(23): usleep(10000)
php#1 example.php(24): recurse()
php#2 example.php(24): recurse()
...
It respects the `zend.exception_ignore_args` INI setting and the
SensitiveParameter attributes, so users can ensure that sensitive
arguments do not end up in the backtrace.
Copy file name to clipboardExpand all lines: ext/standard/tests/general_functions/error_get_last.phpt
+52-1Lines changed: 52 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,18 @@ $a = $b;
15
15
16
16
var_dump(error_get_last());
17
17
18
-
echo"Done\n";
18
+
functiontrigger_fatal_error_with_stacktrace() {
19
+
ini_set('fatal_error_backtraces', true);
20
+
21
+
eval("class Foo {}; class Foo {}");
22
+
}
23
+
24
+
register_shutdown_function(function() {
25
+
var_dump(error_get_last());
26
+
echo"Done\n";
27
+
});
28
+
29
+
trigger_fatal_error_with_stacktrace();
19
30
?>
20
31
--EXPECTF--
21
32
NULL
@@ -33,4 +44,44 @@ array(4) {
33
44
["line"]=>
34
45
int(11)
35
46
}
47
+
48
+
Fatal error: Cannot redeclare class Foo (previously declared in /Users/enorris/workspace/php-src/ext/standard/tests/general_functions/error_get_last.php(18) : eval()'d code:1) in /Users/enorris/workspace/php-src/ext/standard/tests/general_functions/error_get_last.php(18) : eval()'d code on line 1
if (PG(display_errors) && ((module_initialized&& !PG(during_request_startup)) || (PG(display_startup_errors)))) {
1398
1403
if (PG(xmlrpc_errors)) {
1399
-
php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>"ZEND_LONG_FMT"</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %"PRIu32"</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);
1404
+
php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>"ZEND_LONG_FMT"</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %"PRIu32"%s%s</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno, ZSTR_LEN(backtrace) ? "\nStack trace:\n" : "", ZSTR_VAL(backtrace));
php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%"PRIu32"</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), ZSTR_VAL(error_filename), error_lineno, STR_PRINT(append_string));
1408
1413
zend_string_free(buf);
1409
1414
} else {
1410
-
php_printf_unchecked("%s<br />\n<b>%s</b>: %S in <b>%s</b> on line <b>%"PRIu32"</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, message, ZSTR_VAL(error_filename), error_lineno, STR_PRINT(append_string));
1415
+
php_printf_unchecked("%s<br />\n<b>%s</b>: %S in <b>%s</b> on line <b>%"PRIu32"</b><br />%s%s\n%s", STR_PRINT(prepend_string), error_type_str, message, ZSTR_VAL(error_filename), error_lineno, ZSTR_LEN(backtrace) ? "\nStack trace:\n" : "", ZSTR_VAL(backtrace), STR_PRINT(append_string));
1411
1416
}
1412
1417
} else {
1413
1418
/* Write CLI/CGI errors to stderr if display_errors = "stderr" */
fprintf(stderr, " in %s on line %"PRIu32"\n", ZSTR_VAL(error_filename), error_lineno);
1424
+
fprintf(stderr, " in %s on line %"PRIu32"%s%s\n", ZSTR_VAL(error_filename), error_lineno, ZSTR_LEN(backtrace) ? "\nStack trace:\n" : "", ZSTR_VAL(backtrace));
1420
1425
#ifdefPHP_WIN32
1421
1426
fflush(stderr);
1422
1427
#endif
1423
1428
} else {
1424
-
php_printf_unchecked("%s\n%s: %S in %s on line %"PRIu32"\n%s", STR_PRINT(prepend_string), error_type_str, message, ZSTR_VAL(error_filename), error_lineno, STR_PRINT(append_string));
1429
+
php_printf_unchecked("%s\n%s: %S in %s on line %"PRIu32"%s%s\n%s", STR_PRINT(prepend_string), error_type_str, message, ZSTR_VAL(error_filename), error_lineno, ZSTR_LEN(backtrace) ? "\nStack trace:\n" : "", ZSTR_VAL(backtrace), STR_PRINT(append_string));
0 commit comments