Skip to content

Commit

Permalink
Fix adodb_throw() ignoring @ operator on PHP 8
Browse files Browse the repository at this point in the history
error_reporting()'s return value for suppressed errors changed from 0 to
4437 in PHP 8.0.0 [1]. As a result, adodb_throw() throws exceptions when
it is not expected to.

Fixes #981

[1]: https://www.php.net/manual/en/language.operators.errorcontrol.php
  • Loading branch information
dregad committed Jun 10, 2023
1 parent 86234de commit 943ac8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions adodb-exceptions.inc.php
Expand Up @@ -81,10 +81,18 @@ function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)

function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
global $ADODB_EXCEPTION;
global $ADODB_EXCEPTION;

// Do not throw if errors are suppressed by @ operator
// error_reporting() value for suppressed errors changed in PHP 8.0.0
$suppressed = version_compare(PHP_VERSION, '8.0.0', '<')
? 0
: E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
if (error_reporting() == $suppressed) {
return;
}

$errfn = is_string($ADODB_EXCEPTION) ? $ADODB_EXCEPTION : 'ADODB_EXCEPTION';

if (error_reporting() == 0) return; // obey @ protocol
if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
else $errfn = 'ADODB_EXCEPTION';
throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
}
2 changes: 2 additions & 0 deletions docs/changelog.md
Expand Up @@ -33,6 +33,8 @@ Older changelogs:
[#966](https://github.com/ADOdb/ADOdb/issues/966)
- Restore rs2html() $htmlspecialchars param behavior
[#968](https://github.com/ADOdb/ADOdb/issues/968)
- adodb_throw() does not respect @ operator on PHP 8
[#981](https://github.com/ADOdb/ADOdb/issues/981)
- loadbalancer: PHP 8.2 warnings
[#951](https://github.com/ADOdb/ADOdb/issues/951)
- mysql: Fail connection if native driver (mysqlnd) is not available
Expand Down

0 comments on commit 943ac8a

Please sign in to comment.