php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71150 Calling SQLite3::enableExceptions returns previous value instead of new value
Submitted: 2015-12-17 16:30 UTC Modified: 2016-09-11 04:22 UTC
From: bill at zeroedin dot com Assigned: cmb (profile)
Status: No Feedback Package: SQLite related
PHP Version: master-Git-2015-12-17 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bill at zeroedin dot com
New email:
PHP Version: OS:

 

 [2015-12-17 16:30 UTC] bill at zeroedin dot com
Description:
------------
I am documenting the previously undocumented method SQLite3::enableExceptions, and I notice that the method has some weird behavior.

Currently, if you call enableExceptions(true) and exceptions were previously disabled, it returns false. The inverse is also true.

If you call enableExceptions(), it turns off exceptions for the driver and returns whatever value was previously set.

The behavior should be changed to match other similar methods on other drivers.

The method should only change the exception behavior if the $enableExceptions parameter is true or false passed by the user. If no value is passed, the method should return the current state of the flag and take no action. When $enableExceptions is passed by the user, the method should set the value and then return the new value.

Test script:
---------------
$sqlite3 = new SQLite3(':memory:');
var_dump($sqlite3->enableExceptions(true));
var_dump($sqlite3->enableExceptions());
var_dump($sqlite3->enableExceptions());
var_dump($sqlite3->enableExceptions(false));
var_dump($sqlite3->enableExceptions());
var_dump($sqlite3->enableExceptions());

Expected result:
----------------
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)

Actual result:
--------------
bool(false)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-18 02:58 UTC] laruence@php.net
SQLite3::enableException($enable = false);

it returns previously value of enableexception, which default to false.

thanks
 [2016-06-27 15:32 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2016-06-27 15:32 UTC] cmb@php.net
Indeed, this is not a bug, because $enable defaults to false, and
as such the method is not overloaded to work as getter and setter.

> The behavior should be changed to match other similar methods on
> other drivers.

Do other "drivers" work otherwise? Anyhow, I'm changing to
feature request.
 [2016-09-02 19:20 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-09-02 19:20 UTC] cmb@php.net
After further consideration I don't think that changing the
behavior of SQLite3::enableException() is viable (at least not
without an explicit RFC) due to BC concerns.

Furthermore, getting the current state seems to be rarely needed,
and if one needs it, one could still write a function in userland:

  <?php
  function exceptions_enabled() {
      $current = SQLite3::enableException();
      SQLite3::enableException($current);
      return $current;
  }
 [2016-09-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 20:01:45 2024 UTC