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 / policies / ErrorTypeClassifier.php

ErrorTypeClassifier.php in 404 Solution trunk, at includes/policies/ErrorTypeClassifier.php

59 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Classifies PHP error types for shutdown fatal handling.
9 */
10 class ABJ_404_Solution_ErrorTypeClassifier {
11
12 /**
13 * @param int $type PHP error type value.
14 * @return bool
15 */
16 public function isFatalType(int $type): bool {
17 $fatalTypes = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR);
18 return in_array($type, $fatalTypes, true);
19 }
20
21 /**
22 * Recoverable host/infrastructure warnings that PHP reports as E_WARNING
23 * but which the plugin can only degrade past, never fix (the host itself
24 * forbids the operation). These must be logged BELOW error level so
25 * ABJ_404_Solution_DebugLogReader::getLatestErrorLine() -- which keys on the
26 * "(ERROR)" token -- does not count them, and the plugin does not phone
27 * home a type='error' report about a condition only the site owner can
28 * resolve on the server.
29 *
30 * Deliberately a small allowlist seeded by real production reports, not a
31 * blanket downgrade of every E_WARNING: a genuine plugin-code warning (e.g.
32 * "Invalid argument supplied for foreach()") still belongs at error level
33 * so it reaches the maintainer's inbox. Each fragment traces to an incident:
34 * - "headers already sent" report 104 (chasalford.com, 4.2.0, PHP 8.4)
35 * - "open_basedir restriction" report 149 (staging.p2p-game.com, 4.3.2)
36 * Add a fragment here (not a new special case at the call site) when a
37 * future report shows another host-only E_WARNING reaching the error inbox.
38 *
39 * @param int $type PHP error type value (as passed to the error handler).
40 * @param string $message The errstr PHP passed to the error handler.
41 * @return bool
42 */
43 public function isRecoverableHostWarning(int $type, string $message): bool {
44 if ($type !== E_WARNING) {
45 return false;
46 }
47 $hostWarningFragments = array(
48 'Cannot modify header information - headers already sent',
49 'open_basedir restriction in effect',
50 );
51 foreach ($hostWarningFragments as $fragment) {
52 if (strpos($message, $fragment) !== false) {
53 return true;
54 }
55 }
56 return false;
57 }
58 }
59