Skip to content

Commit 0fd9afc

Browse files
committed
Use Error for uninitialized SQLite object
1 parent 876d92b commit 0fd9afc

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...)
6363

6464
#define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \
6565
if (!(db_obj) || !(member)) { \
66-
php_sqlite3_error(db_obj, "The " #class_name " object has not been correctly initialised"); \
67-
RETURN_FALSE; \
66+
zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised"); \
67+
RETURN_THROWS(); \
6868
}
6969

7070
#define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \
7171
if (!(member)) { \
72-
php_error_docref(NULL, E_WARNING, "The " #class_name " object has not been correctly initialised"); \
73-
RETURN_FALSE; \
72+
zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised"); \
73+
RETURN_THROWS(); \
7474
}
7575

7676
/* {{{ PHP_INI */

ext/sqlite3/tests/bug66550.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ $stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
1515
// Close the database connection and free the internal sqlite3_stmt object
1616
$db->close();
1717
// Access the sqlite3_stmt object via the php_sqlite3_stmt container
18-
$stmt->reset();
18+
try {
19+
$stmt->reset();
20+
} catch (\Error $e) {
21+
echo $e->getMessage() . \PHP_EOL;
22+
}
1923
?>
20-
--EXPECTF--
21-
Warning: SQLite3Stmt::reset(): The SQLite3 object has not been correctly initialised in %s
24+
--EXPECT--
25+
The SQLite3 object has not been correctly initialised

ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
2727
echo "Closing database\n";
2828
var_dump($db->close());
2929
echo "Check db was closed\n";
30-
var_dump($results->numColumns());
30+
try {
31+
var_dump($results->numColumns());
32+
} catch (\Error $e) {
33+
echo $e->getMessage() . \PHP_EOL;
34+
}
3135
echo "Done\n";
3236
?>
3337
--EXPECTF--
@@ -46,7 +50,5 @@ array(2) {
4650
Closing database
4751
bool(true)
4852
Check db was closed
49-
50-
Warning: SQLite3Result::numColumns(): The SQLite3Result object has not been correctly initialised in %s on line %d
51-
bool(false)
53+
The SQLite3Result object has not been correctly initialised
5254
Done

0 commit comments

Comments
 (0)