PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / root-boot / BootGuard.php

BootGuard.php in 404 Solution trunk, at includes/root-boot/BootGuard.php

58 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 /**
7 * Boot-failure shutdown handler.
8 *
9 * Defines abj404_boot_shutdown_handler(), which captures compile/parse fatals in
10 * the plugin's files during PHP shutdown and stores them in a transient so the
11 * degraded admin page can display the error on the next request. This matters on
12 * PHP 7.4 where syntax errors in required files produce an uncatchable
13 * E_COMPILE_ERROR.
14 *
15 * The register_shutdown_function() call that wires this handler stays in
16 * 404-solution.php (it must run as part of the boot sequence, before Loader.php
17 * is required). This file only defines the function.
18 */
19 // allow-no-test-found: boot-time global function (abj404_boot_shutdown_handler) wired via register_shutdown_function in 404-solution.php before the autoloader; it captures uncatchable E_COMPILE_ERROR fatals during real PHP shutdown, which cannot be reproduced in-process, so there is no isolated unit seam.
20
21 // Minimal shutdown handler: catches compile/parse fatals in plugin files and
22 // stores them in a transient so the degraded admin page can display the error
23 // on the next request. This is important for PHP 7.4 where syntax errors in
24 // required files produce uncatchable E_COMPILE_ERROR.
25 if (!function_exists('abj404_boot_shutdown_handler')) {
26 /** @return void */
27 function abj404_boot_shutdown_handler() {
28 if ($GLOBALS['abj404_boot_ok']) {
29 return;
30 }
31 $error = error_get_last();
32 if ($error === null) {
33 return;
34 }
35 // Only capture fatal/compile errors in our plugin files.
36 $fatalTypes = E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR;
37 if (!($error['type'] & $fatalTypes)) {
38 return;
39 }
40 $pluginDir = defined('ABJ404_PATH') ? ABJ404_PATH : dirname(dirname(__DIR__)) . '/';
41 if (strpos($error['file'], $pluginDir) === false) {
42 return;
43 }
44 $errorInfo = array(
45 'message' => $error['message'],
46 'file' => $error['file'],
47 'line' => $error['line'],
48 'type' => $error['type'],
49 'time' => abj404_now(),
50 );
51 // Use update_option as a fallback: set_transient might not be available
52 // during a fatal shutdown.
53 if (function_exists('set_transient')) {
54 set_transient('abj404_boot_fatal', $errorInfo, 3600);
55 }
56 }
57 }
58