From 47ac74e6573426dc4d7103a1adcbb7321e9ae76f Mon Sep 17 00:00:00 2001 From: BafS Date: Wed, 21 Jan 2026 18:12:21 +0100 Subject: [PATCH] Fix PHP 8.5 deprecations --- .github/workflows/checks.yml | 6 ++++ lib/avro/datum.php | 6 ++-- test/DatumIOTest.php | 12 ++++---- test/FloatIntEncodingTest.php | 52 +++++++++++++++++------------------ 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0702ca2..06169a7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -40,6 +40,9 @@ jobs: - version: '8.4' xdebug: '3.4.0' + - + version: '8.5' + xdebug: '3.5.0' runs-on: ubuntu-22.04 steps: - @@ -94,6 +97,9 @@ jobs: - version: '8.4' composer: --prefer-stable + - + version: '8.5' + composer: --prefer-stable steps: - name: Download sources diff --git a/lib/avro/datum.php b/lib/avro/datum.php index b328853..8e74252 100644 --- a/lib/avro/datum.php +++ b/lib/avro/datum.php @@ -358,7 +358,7 @@ static function float_to_int_bits($float) */ static function double_to_long_bits($double) { - return pack('d', (double) $double); + return pack('d', (float) $double); } /** @@ -1014,7 +1014,7 @@ static public function int_bits_to_float($bits) static public function long_bits_to_double($bits) { $double = unpack('d', $bits); - return (double) $double[1]; + return (float) $double[1]; } /** @@ -1060,7 +1060,7 @@ public function read_null() { return null; } */ public function read_boolean() { - return (boolean) (1 == ord($this->next_byte())); + return (bool) (1 == ord($this->next_byte())); } /** diff --git a/test/DatumIOTest.php b/test/DatumIOTest.php index a2086c1..c9018af 100644 --- a/test/DatumIOTest.php +++ b/test/DatumIOTest.php @@ -120,11 +120,11 @@ function data_provider() array('"float"', (float) 2.0, "\000\000\000@"), array('"float"', (float) 9.0, "\000\000\020A"), - array('"double"', (double) -10.0, "\000\000\000\000\000\000$\300"), - array('"double"', (double) -1.0, "\000\000\000\000\000\000\360\277"), - array('"double"', (double) 0.0, "\000\000\000\000\000\000\000\000"), - array('"double"', (double) 2.0, "\000\000\000\000\000\000\000@"), - array('"double"', (double) 9.0, "\000\000\000\000\000\000\"@"), + array('"double"', (float) -10.0, "\000\000\000\000\000\000$\300"), + array('"double"', (float) -1.0, "\000\000\000\000\000\000\360\277"), + array('"double"', (float) 0.0, "\000\000\000\000\000\000\000\000"), + array('"double"', (float) 2.0, "\000\000\000\000\000\000\000@"), + array('"double"', (float) 9.0, "\000\000\000\000\000\000\"@"), array('"string"', 'foo', "\x06foo"), array('"bytes"', "\x01\x02\x03", "\x06\x01\x02\x03"), @@ -183,7 +183,7 @@ function default_provider() array('"int"', '1', 1), array('"long"', '2000', 2000), array('"float"', '1.1', (float) 1.1), - array('"double"', '200.2', (double) 200.2), + array('"double"', '200.2', (float) 200.2), array('"string"', '"quux"', 'quux'), array('"bytes"', '"\u00FF"', "\xC3\xBF"), array('{"type":"array","items":"int"}', diff --git a/test/FloatIntEncodingTest.php b/test/FloatIntEncodingTest.php index 035bd4e..349671e 100644 --- a/test/FloatIntEncodingTest.php +++ b/test/FloatIntEncodingTest.php @@ -42,9 +42,9 @@ class FloatIntEncodingTest extends \PHPUnit\Framework\TestCase static function make_special_vals() { - self::$DOUBLE_NAN = (double) NAN; - self::$DOUBLE_POS_INF = (double) INF; - self::$DOUBLE_NEG_INF = (double) -INF; + self::$DOUBLE_NAN = (float) NAN; + self::$DOUBLE_POS_INF = (float) INF; + self::$DOUBLE_NEG_INF = (float) -INF; self::$FLOAT_NAN = (float) NAN; self::$FLOAT_POS_INF = (float) INF; self::$FLOAT_NEG_INF = (float) -INF; @@ -144,29 +144,29 @@ function test_encoding_nan_values($type, $val, $bits) function normal_vals_provider() { return array( - array(self::DOUBLE_TYPE, (double) -10, "\000\000\000\000\000\000$\300", '000000000000420c'), - array(self::DOUBLE_TYPE, (double) -9, "\000\000\000\000\000\000\"\300", '000000000000220c'), - array(self::DOUBLE_TYPE, (double) -8, "\000\000\000\000\000\000 \300", '000000000000020c'), - array(self::DOUBLE_TYPE, (double) -7, "\000\000\000\000\000\000\034\300", '000000000000c10c'), - array(self::DOUBLE_TYPE, (double) -6, "\000\000\000\000\000\000\030\300", '000000000000810c'), - array(self::DOUBLE_TYPE, (double) -5, "\000\000\000\000\000\000\024\300", '000000000000410c'), - array(self::DOUBLE_TYPE, (double) -4, "\000\000\000\000\000\000\020\300", '000000000000010c'), - /**/ array(self::DOUBLE_TYPE, (double) -3, "\000\000\000\000\000\000\010\300", '000000000000800c'), - array(self::DOUBLE_TYPE, (double) -2, "\000\000\000\000\000\000\000\300", '000000000000000c'), - array(self::DOUBLE_TYPE, (double) -1, "\000\000\000\000\000\000\360\277", '0000000000000ffb'), - array(self::DOUBLE_TYPE, (double) 0, "\000\000\000\000\000\000\000\000", '0000000000000000'), - array(self::DOUBLE_TYPE, (double) 1, "\000\000\000\000\000\000\360?", '0000000000000ff3'), - array(self::DOUBLE_TYPE, (double) 2, "\000\000\000\000\000\000\000@", '0000000000000004'), - /**/ array(self::DOUBLE_TYPE, (double) 3, "\000\000\000\000\000\000\010@", '0000000000008004'), - array(self::DOUBLE_TYPE, (double) 4, "\000\000\000\000\000\000\020@", '0000000000000104'), - array(self::DOUBLE_TYPE, (double) 5, "\000\000\000\000\000\000\024@", '0000000000004104'), - array(self::DOUBLE_TYPE, (double) 6, "\000\000\000\000\000\000\030@", '0000000000008104'), - array(self::DOUBLE_TYPE, (double) 7, "\000\000\000\000\000\000\034@", '000000000000c104'), - array(self::DOUBLE_TYPE, (double) 8, "\000\000\000\000\000\000 @", '0000000000000204'), - array(self::DOUBLE_TYPE, (double) 9, "\000\000\000\000\000\000\"@", '0000000000002204'), - array(self::DOUBLE_TYPE, (double) 10, "\000\000\000\000\000\000$@", '0000000000004204'), - /**/ array(self::DOUBLE_TYPE, (double) -1234.2132, "\007\316\031Q\332H\223\300", '70ec9115ad84390c'), - array(self::DOUBLE_TYPE, (double) -2.11e+25, "\311\260\276J\031t1\305", '9c0beba49147135c'), + array(self::DOUBLE_TYPE, (float) -10, "\000\000\000\000\000\000$\300", '000000000000420c'), + array(self::DOUBLE_TYPE, (float) -9, "\000\000\000\000\000\000\"\300", '000000000000220c'), + array(self::DOUBLE_TYPE, (float) -8, "\000\000\000\000\000\000 \300", '000000000000020c'), + array(self::DOUBLE_TYPE, (float) -7, "\000\000\000\000\000\000\034\300", '000000000000c10c'), + array(self::DOUBLE_TYPE, (float) -6, "\000\000\000\000\000\000\030\300", '000000000000810c'), + array(self::DOUBLE_TYPE, (float) -5, "\000\000\000\000\000\000\024\300", '000000000000410c'), + array(self::DOUBLE_TYPE, (float) -4, "\000\000\000\000\000\000\020\300", '000000000000010c'), + /**/ array(self::DOUBLE_TYPE, (float) -3, "\000\000\000\000\000\000\010\300", '000000000000800c'), + array(self::DOUBLE_TYPE, (float) -2, "\000\000\000\000\000\000\000\300", '000000000000000c'), + array(self::DOUBLE_TYPE, (float) -1, "\000\000\000\000\000\000\360\277", '0000000000000ffb'), + array(self::DOUBLE_TYPE, (float) 0, "\000\000\000\000\000\000\000\000", '0000000000000000'), + array(self::DOUBLE_TYPE, (float) 1, "\000\000\000\000\000\000\360?", '0000000000000ff3'), + array(self::DOUBLE_TYPE, (float) 2, "\000\000\000\000\000\000\000@", '0000000000000004'), + /**/ array(self::DOUBLE_TYPE, (float) 3, "\000\000\000\000\000\000\010@", '0000000000008004'), + array(self::DOUBLE_TYPE, (float) 4, "\000\000\000\000\000\000\020@", '0000000000000104'), + array(self::DOUBLE_TYPE, (float) 5, "\000\000\000\000\000\000\024@", '0000000000004104'), + array(self::DOUBLE_TYPE, (float) 6, "\000\000\000\000\000\000\030@", '0000000000008104'), + array(self::DOUBLE_TYPE, (float) 7, "\000\000\000\000\000\000\034@", '000000000000c104'), + array(self::DOUBLE_TYPE, (float) 8, "\000\000\000\000\000\000 @", '0000000000000204'), + array(self::DOUBLE_TYPE, (float) 9, "\000\000\000\000\000\000\"@", '0000000000002204'), + array(self::DOUBLE_TYPE, (float) 10, "\000\000\000\000\000\000$@", '0000000000004204'), + /**/ array(self::DOUBLE_TYPE, (float) -1234.2132, "\007\316\031Q\332H\223\300", '70ec9115ad84390c'), + array(self::DOUBLE_TYPE, (float) -2.11e+25, "\311\260\276J\031t1\305", '9c0beba49147135c'), array(self::FLOAT_TYPE, (float) -10, "\000\000 \301", '0000021c'), array(self::FLOAT_TYPE, (float) -9, "\000\000\020\301", '0000011c'),