Fix a PHP 8.5 chr() deprecation when decoding octal string escapes#4842
Merged
Conversation
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).
e80fc2c to
153094b
Compare
Contributor
|
Thank you @austinderrick. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP 8.5 deprecates passing a value outside the
[0, 255]range tochr().The string-escape decoder in
Lexer::stringEscape()accepts up to three octal digits, so a template containing an escape such as"\777"(= 511) reacheschr()out of range and emits:chr()already constrains the value with% 256, so applying% 256explicitly 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 to0xff) and"\400"(wraps to a NUL byte). The full suite passes on PHP 8.5; without this change the bridge reports thechr()notice as a self-deprecation.