Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BitArray/BitArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public function applyComplement()
$length = strlen($this->data);

for ($index = 0; $index < $length; $index++) {
$this->data[$index] = chr(~ ord($this->data[$index]));
$this->data[$index] = chr((~ ord($this->data[$index])) & 0xFF);
}

return $this->restrict();
Expand Down
35 changes: 35 additions & 0 deletions tests/BitArray/BitArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,41 @@ public function testApplyComplement()
);
}

/**
* Tests BitArray::applyComplement does not trigger a deprecation on PHP 8.5
*
* @return void
*/
public function testApplyComplementDoesNotTriggerDeprecation()
{
if (PHP_VERSION_ID < 80500) {
$this->markTestSkipped('This test requires PHP 8.5 or later');
}

set_error_handler(
static function (
int $severity,
string $message,
string $filename,
int $line
): never {
throw new \ErrorException($message, 0, $severity, $filename, $line);
},
E_DEPRECATED
);

try {
$bits = BitArray::fromString('10011');

$this->assertEquals(
'01100',
(string) $bits->applyComplement()
);
} finally {
restore_error_handler();
}
}

/**
* Tests BitArray::applyOr
*
Expand Down
Loading