rfc:sqlite3_exceptions

This is an old revision of the document!


PHP RFC: Use exceptions by default in SQLite3 extension

Introduction

The SQLite3 extension is still using PHP warnings by default. PDO is using exceptions, like everyone else.

It's time to move to exceptions.

Proposal

  • Create a new exception class SQLite3Exception, which extends the SPL RuntimeException class, like in mysqli and PDO
  • Make SQLite3 throw exceptions of class SQLite3Exception by default
  • Remove the SQLite3::enableExceptions method
  • Remove SQLite3 error code from the error message, and assign it to the exception code

Backward Incompatible Changes

  • Calls to SQLite3::enableExceptions will break, but can be easily removed, or made optional using method_exists
  • Code relying on hiding warnings will break
  • Code already relying on exceptions will not see a difference, as previously \Exception was thrown, and \SQLite3Exception is a subclass of \Exception
  • Code parsing the error message to get the error code (??)

The soft option would be to keep the enableExceptions method for one version, but make throwing SQLite3Exceptions the default behaviour, and then remove enableExceptions in following version.

Proposed PHP Version(s)

Next PHP 8.x (8.3?)

RFC Impact

To SAPIs

None.

To Existing Extensions

Only SQLite3.

To Opcache

None that I can think of.

New Constants

None.

php.ini Defaults

None.

Unaffected PHP Functionality

Everything outside of SQLite3 extension.

Future Scope

Assign SQLite3 error constants to SQLite3Exception class, eg. SQLite3Exception::READONLY, see https://www.sqlite.org/rescode.html

Proposed Voting Choices

  • Proposal 1: in 8.3 remove enableExceptions, throw SQLite3Exception by default
  • Proposal 2: in 8.3 deprecate enableExceptions, throw SQLite3Exception by default, but allow to keep warnings instead of exceptions (but deprecate it), then in 8.4 remove enableExceptions and warnings
  • Choice 3: no change

Patches and Tests

Pull request: https://github.com/php/php-src/pull/9816 (proposal 1)

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/sqlite3_exceptions.1666579944.txt.gz · Last modified: 2022/10/24 02:52 by bohwaz