Silence PHP 8.5 chr() deprecation in encodeInt8#145
Merged
Conversation
…tion
PHP 8.5 deprecates chr() with values outside [0, 255] (modulo-256 silent
fallback). encodeInt8 is called from MysqlEncodedValue::fromValue for int
parameters in [-128, 127] (the Tiny branch), and from encodeInt for length
prefixes up to 250, so it routinely receives negative ints that trigger
the warning.
pack("C", $int) produces the same byte across the full input range and
matches the existing pack-family idiom used by encodeInt16/24/32:
encodeInt16 → \pack("v", $int)
encodeInt24 → \substr(\pack("V", $int), 0, 3)
encodeInt32 → \pack("V", $int)
encodeInt8 → \pack("C", $int) (this commit)
Verified bit-identical to the old chr() output for the full [-128, 255]
input range, no behavior change.
Member
|
Thanks! |
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
chr()with values outside[0, 255]. The warning fires fromsrc/MysqlDataType.php:521becauseencodeInt8receives negative ints fromMysqlEncodedValue::fromValue()for theTinybranch (parameters in[-128, 127]).The fix swaps
\chr($int)for\pack("C", $int), which produces the same byte across the full input range and isn't deprecated. It's also consistent with the existing idiom in this file:Verification
Bit-identical output across the full input range that
encodeInt8actually sees ([-128, 250]):A direct smoke test of the swapped function:
No deprecation triggered after the change.
The other
\chr()call sites in the codebase (src/Internal/ConnectionProcessor.php) all pass small non-negative values (cursor flags, bind counts, charset constants, length bytes) and don't trigger the deprecation, so they're left alone.