Skip to content

Commit

Permalink
Fix "Only the first byte will be assigned to the string offset"
Browse files Browse the repository at this point in the history
Occurs in PHP 8.0
  • Loading branch information
thekid committed Apr 10, 2020
1 parent a2362e6 commit cf67a9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 6 additions & 11 deletions src/main/php/peer/net/Inet6Address.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf67a9b

Please sign in to comment.