-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
When using SQLite3 's execute function, the PHP doc's declaration states it returns a SQLite3Result object but the text of the document declares that it can return false if it failed. PHPStan rejects checking if the result of a SQLite3 execute is false.
Strict comparison using === between SQLite3Result and false will always evaluate to false.
<?php declare(strict_types = 1);
class CacheAPC extends \SQLite3
{
/**
* Constructor
*/
public function __construct()
{
define("PERMISSION_FILE", 'preferences.db');
if (!\file_exists(PERMISSION_FILE)) {
\touch(PERMISSION_FILE, \time());
\chmod(PERMISSION_FILE, 0600);
}
parent::__construct(
PERMISSION_FILE,
SQLITE3_OPEN_READWRITE,
null
);
}
}
$db = new CacheAPC();
if ($db !== false) {
$stmt = $db->prepare("INSERT INTO TEST_TABLE (FIELD_1) VALUES (:field1);");
if ($stmt !== false) {
$value = 1;
$stmt->bindParam(':field1', $value);
$ret = $stmt->execute();
if ($ret === false) {
throw new \Exception("Failed to insert");
}
}
}Unique URL: https://phpstan.org/r/951545c0-9089-40e6-b136-3c1def3713a4
Expected output
PHPStan should not raise an issue, it should accept that execute can return false.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels