Skip to content

Commit d2c7bfe

Browse files
authored
Fix PHP highlighting for PHP ≥ 8.3 (GH-156)
PHP 8.3 changed the details of highlighting PHP code[1], basically like we did[2] at roughly the same time. However, both don't work well together, so we avoid that. [1] <php/php-src#11913> [2] <#79>
1 parent 417b066 commit d2c7bfe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

phpdotnet/phd/Highlighter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ public function highlight($text, $role, $format)
6363

6464
if ($role == 'php') {
6565
try {
66-
return strtr(highlight_string($text, 1), [
67-
'&nbsp;' => ' ',
68-
"\n" => '',
69-
]);
66+
$highlight = highlight_string($text, true);
67+
if (PHP_VERSION_ID >= 80300) {
68+
return $highlight;
69+
} else {
70+
return strtr($highlight, [
71+
'&nbsp;' => ' ',
72+
"\n" => '',
73+
]);
74+
}
7075
} catch (\ParseException $e) {
7176
v("Parse error while highlighting PHP code: %s\nText: %s", (string) $e, $text, E_USER_WARNING);
7277

0 commit comments

Comments
 (0)