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 27, 2019
1 parent dd75e74 commit 7e705c5
Show file tree
Hide file tree
Showing 2 changed files with 12 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
7 changes: 6 additions & 1 deletion tests/Database/Row.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ 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)
if (PHP_VERSION_ID > 70300) {
Assert::false(isset($row['0'])); // this is buggy since PHP 5.4 (bug #63217) to PHP 7.2
}
Assert::false(isset($row[1])); // null value
Assert::false(isset($row[2])); // is not set

Expand Down

0 comments on commit 7e705c5

Please sign in to comment.