Fabien Potencier 8a93950693 bug #4842 Fix a PHP 8.5 chr() deprecation when decoding octal string escapes (austinderrick)
This PR was merged into the 3.x branch.

Discussion
----------

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

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):

```twig
{{ "\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.

Commits
-------

153094b601 Fix a PHP 8.5 chr() deprecation when decoding octal string escapes
2026-06-13 07:22:34 +02:00
2026-02-07 09:07:38 +01:00
2026-02-07 09:12:49 +01:00
2024-11-20 20:05:33 +01:00

Twig, the flexible, fast, and secure template language for PHP
==============================================================

Twig is a template language for PHP.

Twig uses a syntax similar to the Django and Jinja template languages which
inspired the Twig runtime environment.

Sponsors
--------

.. raw:: html

    <a href="https://docs.blackfire.io/introduction?utm_source=twig&utm_medium=github_readme&utm_campaign=logo">
        <img src="https://static.blackfire.io/assets/intemporals/logo/png/blackfire-io_secondary_horizontal_transparent.png?1" width="255px" alt="Blackfire.io">
    </a>

More Information
----------------

Read the `documentation`_ for more information.

.. _documentation: https://twig.symfony.com/documentation
Languages
PHP 99.9%