Skip to content

Commit

Permalink
Row: compatibility with operator ??
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 25, 2019
1 parent dd75e74 commit cce6a9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Database/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function __get($key)
}


public function __isset($key)
{
return isset($this->key);
}


/**
* Returns a item.
* @param string|int $key key or index
Expand Down
5 changes: 4 additions & 1 deletion tests/Database/Row.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ test(function () use ($connection) { // numeric field
Assert::same(123, $row->{123});
Assert::same(123, $row->{'123'});
Assert::true(isset($row->{123}));
Assert::same(123, $row->{123} ?? 'default');
Assert::false(isset($row->{1}));
Assert::same('default', $row->{1} ?? 'default');
Assert::same('default', $row->nullcol ?? 'default');

Assert::same(123, $row[0]);
Assert::true(isset($row[0]));
Assert::false(isset($row[123]));
//Assert::false(isset($row['0'])); // this is buggy since PHP 5.4 (bug #63217)
Assert::false(isset($row['0']));
Assert::false(isset($row[1])); // null value
Assert::false(isset($row[2])); // is not set

Expand Down

0 comments on commit cce6a9c

Please sign in to comment.