Skip to content

Commit c11f95e

Browse files
authored
Merge pull request #553 from mcg-web/add_message_level
Add message level when using custom warning handler
2 parents fba3ee9 + 96db5d2 commit c11f95e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Error/Warning.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,26 @@ public static function enable($enable = true) : void
9696

9797
public static function warnOnce(string $errorMessage, int $warningId, ?int $messageLevel = null) : void
9898
{
99+
$messageLevel = $messageLevel ?: E_USER_WARNING;
100+
99101
if (self::$warningHandler !== null) {
100102
$fn = self::$warningHandler;
101-
$fn($errorMessage, $warningId);
103+
$fn($errorMessage, $warningId, $messageLevel);
102104
} elseif ((self::$enableWarnings & $warningId) > 0 && ! isset(self::$warned[$warningId])) {
103105
self::$warned[$warningId] = true;
104-
trigger_error($errorMessage, $messageLevel ?: E_USER_WARNING);
106+
trigger_error($errorMessage, $messageLevel);
105107
}
106108
}
107109

108110
public static function warn(string $errorMessage, int $warningId, ?int $messageLevel = null) : void
109111
{
112+
$messageLevel = $messageLevel ?: E_USER_WARNING;
113+
110114
if (self::$warningHandler !== null) {
111115
$fn = self::$warningHandler;
112-
$fn($errorMessage, $warningId);
116+
$fn($errorMessage, $warningId, $messageLevel);
113117
} elseif ((self::$enableWarnings & $warningId) > 0) {
114-
trigger_error($errorMessage, $messageLevel ?: E_USER_WARNING);
118+
trigger_error($errorMessage, $messageLevel);
115119
}
116120
}
117121
}

0 commit comments

Comments
 (0)