diff --git a/ChangeLog.md b/ChangeLog.md index 6e0311f..ef27f1d 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,6 +5,9 @@ Networking changelog ## 10.0.0 / 2020-04-10 +* Fixed "Only the first byte will be assigned to the string offset" + warning in PHP 8.0 + (@thekid) * Implemented xp-framework/rfc#334: Drop PHP 5.6: . **Heads up:** Minimum required PHP version now is PHP 7.0.0 . Rewrote code base, grouping use statements diff --git a/src/main/php/peer/net/Inet6Address.class.php b/src/main/php/peer/net/Inet6Address.class.php index 2166232..a125756 100755 --- a/src/main/php/peer/net/Inet6Address.class.php +++ b/src/main/php/peer/net/Inet6Address.class.php @@ -164,26 +164,21 @@ public function createSubnet($subnetSize) { $addr= $this->addr; for ($i= 15; $i >= $subnetSize / 8; --$i) { - $addr[$i]= "\x0"; + $addr[$i]= "\0"; } - if($subnetSize%8 > 0) { - $lastNibblePos= (int)($subnetSize/8); - $lastByte= ord($addr[$lastNibblePos]) & (0xFF << (8 - $subnetSize % 8)); - $addr[$lastNibblePos]= pack('i*', $lastByte); + if($subnetSize % 8 > 0) { + $lastNibblePos= (int)($subnetSize / 8); + $addr[$lastNibblePos]= chr(ord($addr[$lastNibblePos]) & (0xFF << (8 - $subnetSize % 8))); } return new Network(new Inet6Address($addr, true), $subnetSize); } /** @return string */ - public function toString() { - return nameof($this).'('.$this->asString().')'; - } + public function toString() { return nameof($this).'('.$this->asString().')'; } /** @return string */ - public function hashCode() { - return $this->asString(); - } + public function hashCode() { return $this->asString(); } /** * Compare