Skip to content

Commit 307e194

Browse files
committed
fix: preg_last_error_msg() can be used in PHP 8.0 or later
1 parent bbfd392 commit 307e194

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

system/Autoloader/Autoloader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,13 @@ public function sanitizeFilename(string $filename): string
318318
);
319319
}
320320
if ($result === false) {
321-
throw new RuntimeException(preg_last_error_msg() . ' filename: "' . $filename . '"');
321+
if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
322+
$message = preg_last_error_msg();
323+
} else {
324+
$message = 'Regex error. error code: ' . preg_last_error();
325+
}
326+
327+
throw new RuntimeException($message . '. filename: "' . $filename . '"');
322328
}
323329

324330
// Clean up our filename edges.

tests/system/Autoloader/AutoloaderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ public function testSanitizationFilenameEdges()
226226
public function testSanitizationRegexError()
227227
{
228228
$this->expectException(RuntimeException::class);
229-
$this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded filename:');
230229

231230
$test = mb_convert_encoding('クラスファイル.php', 'EUC-JP', 'UTF-8');
232231

0 commit comments

Comments
 (0)