Skip to content

Commit cce6a9c

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

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Database/Row.php

+6
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ 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+
Assert::false(isset($row['0']));
2629
Assert::false(isset($row[1])); // null value
2730
Assert::false(isset($row[2])); // is not set
2831

0 commit comments

Comments
 (0)