Skip to content

Commit 6408c20

Browse files
committed
fix TypeError under php8.0 ($this->result can be false)
1 parent 07fceef commit 6408c20

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/QrReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function text()
9191
{
9292
$this->decode();
9393

94-
if (method_exists($this->result, 'toString')) {
94+
if ($this->result && method_exists($this->result, 'toString')) {
9595
return $this->result->toString();
9696
}
9797

tests/QrReaderTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ public function testText1()
1515
$qrcode = new QrReader($image);
1616
$this->assertSame("Hello world!", $qrcode->text());
1717
}
18+
19+
public function testNoText()
20+
{
21+
$image = __DIR__ . "/qrcodes/empty.png";
22+
$qrcode = new QrReader($image);
23+
$this->assertSame(false, $qrcode->text());
24+
}
1825
}

tests/qrcodes/empty.png

1.56 KB
Loading

0 commit comments

Comments
 (0)