diff --git a/src/Database/Row.php b/src/Database/Row.php index 960248aa4..b18f7e9bf 100644 --- a/src/Database/Row.php +++ b/src/Database/Row.php @@ -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 diff --git a/tests/Database/Row.phpt b/tests/Database/Row.phpt index e68702d53..2644be21a 100644 --- a/tests/Database/Row.phpt +++ b/tests/Database/Row.phpt @@ -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