Skip to content

Commit

Permalink
Only check for null in get/set
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Apr 2, 2024
1 parent 36cd440 commit 032b88d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/WeakMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function offsetExists($object) : bool
public function offsetGet($object)
{
$this->housekeeping();
$this->assertValidKey($object);
$this->assertValidKey($object, true);

$id = spl_object_id($object);

Expand All @@ -139,7 +139,7 @@ public function offsetGet($object)
public function offsetSet($object, $value) : void
{
$this->housekeeping();
$this->assertValidKey($object);
$this->assertValidKey($object, true);

$id = spl_object_id($object);

Expand Down Expand Up @@ -230,9 +230,9 @@ private function housekeeping(bool $force = false) : void
/**
* @param mixed $key
*/
private function assertValidKey($key) : void
private function assertValidKey($key, bool $checkNull = false) : void
{
if ($key === null) {
if ($checkNull && $key === null) {
throw new Error('Cannot append to WeakMap');
}

Expand Down

0 comments on commit 032b88d

Please sign in to comment.