Skip to content

Fix a PHP 8.5 chr() deprecation when decoding octal string escapes#4842

Merged
fabpot merged 1 commit into
twigphp:3.xfrom
austinderrick:fix-php85-chr-octal-escape
Jun 13, 2026
Merged

Fix a PHP 8.5 chr() deprecation when decoding octal string escapes#4842
fabpot merged 1 commit into
twigphp:3.xfrom
austinderrick:fix-php85-chr-octal-escape

Conversation

@austinderrick

Copy link
Copy Markdown
Contributor

PHP 8.5 deprecates passing a value outside the [0, 255] range to chr().

The string-escape decoder in Lexer::stringEscape() accepts up to three octal digits, so a template containing an escape such as "\777" (= 511) reaches chr() out of range and emits:

chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value must be in the [0, 255] interval. The value used will be constrained using % 256

chr() already constrains the value with % 256, so applying % 256 explicitly preserves the exact byte that was produced before while silencing the deprecation. The hex-escape branch is unaffected because it is capped at two digits (\xff = 255).

Reproducer (PHP 8.5):

{{ "\777" }}

Tests added to getStringWithEscapedDelimiter() cover "\777" (constrained to 0xff) and "\400" (wraps to a NUL byte). The full suite passes on PHP 8.5; without this change the bridge reports the chr() notice as a self-deprecation.

PHP 8.5 deprecates passing a value outside the [0, 255] range to chr().
The string-escape decoder in the lexer accepts up to three octal digits,
so an escape such as "\777" (= 511) reaches chr() out of range and emits:

    chr(): Providing a value not in-between 0 and 255 is deprecated ...

chr() already constrains the value with "% 256", so applying "% 256"
explicitly preserves the exact byte while silencing the deprecation. The
hex escape branch is unaffected because it is capped at two digits (0xff).
@fabpot fabpot force-pushed the fix-php85-chr-octal-escape branch from e80fc2c to 153094b Compare June 13, 2026 05:22
@fabpot

fabpot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Thank you @austinderrick.

@fabpot fabpot merged commit 8a93950 into twigphp:3.x Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants