Skip to content

Commit 7e705c5

Browse files
committed
Row: compatibility with operator ??
1 parent dd75e74 commit 7e705c5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Database/Row.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public function __get($key)
2424
}
2525

2626

27+
public function __isset($key)
28+
{
29+
return isset($this->key);
30+
}
31+
32+
2733
/**
2834
* Returns a item.
2935
* @param string|int $key key or index

tests/Database/Row.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ test(function () use ($connection) { // numeric field
1717
Assert::same(123, $row->{123});
1818
Assert::same(123, $row->{'123'});
1919
Assert::true(isset($row->{123}));
20+
Assert::same(123, $row->{123} ?? 'default');
2021
Assert::false(isset($row->{1}));
22+
Assert::same('default', $row->{1} ?? 'default');
23+
Assert::same('default', $row->nullcol ?? 'default');
2124

2225
Assert::same(123, $row[0]);
2326
Assert::true(isset($row[0]));
2427
Assert::false(isset($row[123]));
25-
//Assert::false(isset($row['0'])); // this is buggy since PHP 5.4 (bug #63217)
28+
if (PHP_VERSION_ID > 70300) {
29+
Assert::false(isset($row['0'])); // this is buggy since PHP 5.4 (bug #63217) to PHP 7.2
30+
}
2631
Assert::false(isset($row[1])); // null value
2732
Assert::false(isset($row[2])); // is not set
2833

0 commit comments

Comments
 (0)