Skip to content

Commit f483081

Browse files
authored
Mask chr input to prevent deprecation warnings on PHP 8.5 (#40)
1 parent f0befd7 commit f483081

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

.github/workflows/qa.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- PHP_IMAGE: php:8.2-cli
2424
- PHP_IMAGE: php:8.3-cli
2525
- PHP_IMAGE: php:8.4-cli
26+
- PHP_IMAGE: php:8.5-cli
2627

2728
runs-on: ${{ matrix.operating-system }}
2829
steps:

src/Packer.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function packInt($int)
177177
return "\xcc".\chr($int);
178178
}
179179
if ($int <= 0xffff) {
180-
return "\xcd".\chr($int >> 8).\chr($int);
180+
return "\xcd".\chr($int >> 8).\chr($int & 0xff);
181181
}
182182
if ($int <= 0xffffffff) {
183183
return \pack('CN', 0xce, $int);
@@ -187,13 +187,13 @@ public function packInt($int)
187187
}
188188

189189
if ($int >= -0x20) {
190-
return \chr(0xe0 | $int);
190+
return \chr(0xe0 | $int & 0xff);
191191
}
192192
if ($int >= -0x80) {
193-
return "\xd0".\chr($int);
193+
return "\xd0".\chr($int & 0xff);
194194
}
195195
if ($int >= -0x8000) {
196-
return "\xd1".\chr($int >> 8).\chr($int);
196+
return "\xd1".\chr($int >> 8 & 0xff).\chr($int & 0xff);
197197
}
198198
if ($int >= -0x80000000) {
199199
return \pack('CN', 0xd2, $int);
@@ -250,7 +250,7 @@ public function packStr($str)
250250
return "\xd9".\chr($length).$str;
251251
}
252252
if ($length <= 0xffff) {
253-
return "\xda".\chr($length >> 8).\chr($length).$str;
253+
return "\xda".\chr($length >> 8).\chr($length & 0xff).$str;
254254
}
255255

256256
return \pack('CN', 0xdb, $length).$str;
@@ -269,7 +269,7 @@ public function packBin($str)
269269
return "\xc4".\chr($length).$str;
270270
}
271271
if ($length <= 0xffff) {
272-
return "\xc5".\chr($length >> 8).\chr($length).$str;
272+
return "\xc5".\chr($length >> 8).\chr($length & 0xff).$str;
273273
}
274274

275275
return \pack('CN', 0xc6, $length).$str;
@@ -302,7 +302,7 @@ public function packArrayHeader($size)
302302
return \chr(0x90 | $size);
303303
}
304304
if ($size <= 0xffff) {
305-
return "\xdc".\chr($size >> 8).\chr($size);
305+
return "\xdc".\chr($size >> 8).\chr($size & 0xff);
306306
}
307307

308308
return \pack('CN', 0xdd, $size);
@@ -356,7 +356,7 @@ public function packMapHeader($size)
356356
return \chr(0x80 | $size);
357357
}
358358
if ($size <= 0xffff) {
359-
return "\xde".\chr($size >> 8).\chr($size);
359+
return "\xde".\chr($size >> 8).\chr($size & 0xff);
360360
}
361361

362362
return \pack('CN', 0xdf, $size);
@@ -373,15 +373,15 @@ public function packExt($type, $data)
373373
$length = \strlen($data);
374374

375375
switch ($length) {
376-
case 1: return "\xd4".\chr($type).$data;
377-
case 2: return "\xd5".\chr($type).$data;
378-
case 4: return "\xd6".\chr($type).$data;
379-
case 8: return "\xd7".\chr($type).$data;
380-
case 16: return "\xd8".\chr($type).$data;
376+
case 1: return "\xd4".\chr($type & 0xff).$data;
377+
case 2: return "\xd5".\chr($type & 0xff).$data;
378+
case 4: return "\xd6".\chr($type & 0xff).$data;
379+
case 8: return "\xd7".\chr($type & 0xff).$data;
380+
case 16: return "\xd8".\chr($type & 0xff).$data;
381381
}
382382

383383
if ($length <= 0xff) {
384-
return "\xc7".\chr($length).\chr($type).$data;
384+
return "\xc7".\chr($length).\chr($type & 0xff).$data;
385385
}
386386
if ($length <= 0xffff) {
387387
return \pack('CnC', 0xc8, $length, $type).$data;

0 commit comments

Comments
 (0)