This is an old revision of the document!
PHP RFC: use Exceptions in SQLite3
- Version: 0.1
- Date: 2022-10-24
- Author: BohwaZ, php at bohwaz dot net
- Status: Under discussion
- First Published at: http://wiki.php.net/rfc/sqlite3_exceptions
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, like mysqli and PDO
- Make SQLite3 throw exceptions of class SQLite3Exception by default
- Remove the SQLite3::enableExceptions method
- Move SQLite error code off the error message 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
Another option could be to keep the enableExceptions method for one version, but make throwing SQLite3Exceptions the default behaviour.
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
- the version(s) it was merged into
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
- 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.