# PhpHighlighter

> Renders a captured value as syntax-highlighted PHP, the way the Dump panel presents its payloads.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Helper](/docs/extensions/debug-core/reference/helper/index.md) › PhpHighlighter

| final class | `PHPForge\Debug\Helper\PhpHighlighter` |
| --- | --- |
| Source | [`src/Helper/PhpHighlighter.php`](https://github.com/php-forge/debug-core/blob/main/src/Helper/PhpHighlighter.php#L13) |

Renders a captured value as syntax-highlighted PHP, the way the Dump panel presents its payloads.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`highlight()`](#method-highlight) static | Highlights a value as the PHP expression that would recreate it. | `PhpHighlighter` |
| [`highlightCode()`](#method-highlightCode) static | Highlights PHP source text, such as the `var_export()` output carried by a log message. | `PhpHighlighter` |

## Method details

### highlight() <span id="method-highlight"></span>

```php
public static function highlight(mixed $value): string
```

Highlights a value as the PHP expression that would recreate it.

The expression is built here with [`Dump::export()`](/docs/extensions/debug-core/reference/helper/dump/index.md#method-export) and handed to [`PhpHighlighter::highlightCode()`](/docs/extensions/debug-core/reference/helper/phphighlighter/index.md#method-highlightCode), so the result
carries no markup from the captured value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | JSON-safe value to render. |

**Returns**

`string`: Highlighted markup in a focusable `<pre>`, without the opening tag PHP needs to recognize the snippet.

### highlightCode() <span id="method-highlightCode"></span>

```php
public static function highlightCode(string $code): string
```

Highlights PHP source text, such as the `var_export()` output carried by a log message.

PHP's highlighter escapes the whole source, so markup carried by the text renders as text and never as markup.
The source is only highlighted, never evaluated.

The `<pre>` wrapper scrolls horizontally, so it carries `tabindex="0"` to stay reachable by keyboard.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$code` | `string` | PHP source of an expression, without the opening tag. |

**Returns**

`string`: Highlighted markup in a focusable `<pre>`, without the opening tag PHP needs to recognize the snippet.