Skip to content

Commit 14c044a

Browse files
committed
Avoid chr() deprecation warnings in PHP 8.5
1 parent d01a499 commit 14c044a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Binary.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static function readSignedByte(string $c) : int{
142142
* Writes an unsigned/signed byte
143143
*/
144144
public static function writeByte(int $c) : string{
145-
return chr($c);
145+
return chr($c & 0xff);
146146
}
147147

148148
/**
@@ -434,10 +434,11 @@ public static function writeUnsignedVarInt(int $value) : string{
434434
$buf = "";
435435
$remaining = $value & 0xffffffff;
436436
for($i = 0; $i < 5; ++$i){
437+
$bits = $remaining & 0x7f;
437438
if(($remaining >> 7) !== 0){
438-
$buf .= chr($remaining | 0x80);
439+
$buf .= chr($bits | 0x80);
439440
}else{
440-
$buf .= chr($remaining & 0x7f);
441+
$buf .= chr($bits & 0x7f);
441442
return $buf;
442443
}
443444

@@ -498,10 +499,11 @@ public static function writeUnsignedVarLong(int $value) : string{
498499
$buf = "";
499500
$remaining = $value;
500501
for($i = 0; $i < 10; ++$i){
502+
$bits = $remaining & 0x7f;
501503
if(($remaining >> 7) !== 0){
502-
$buf .= chr($remaining | 0x80); //Let chr() take the last byte of this, it's faster than adding another & 0x7f.
504+
$buf .= chr($bits | 0x80);
503505
}else{
504-
$buf .= chr($remaining & 0x7f);
506+
$buf .= chr($bits & 0x7f);
505507
return $buf;
506508
}
507509

src/BinaryStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getByte() : int{
119119
}
120120

121121
public function putByte(int $v) : void{
122-
$this->buffer .= chr($v);
122+
$this->buffer .= chr($v & 0xff);
123123
}
124124

125125
/**

0 commit comments

Comments
 (0)