Skip to content

Commit 3a31c40

Browse files
committed
DB::on_error closure support
closure is now supported for `DB::on_error`
1 parent f48063d commit 3a31c40

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/DB.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,17 @@ public function run($sql = '', $bind = null, $args = null, $style = null) {
311311
* Callback function.
312312
*/
313313
public function on_error($error_callback) {
314-
// Variable functions for won't work with language constructs such as echo
315-
// and print, so these are replaced with print_r.
316-
if (in_array(strtolower($error_callback), ['echo', 'print'])) {
317-
$error_callback = 'print_r';
318-
}
314+
if (is_string($error_callback)) {
315+
// Variable functions for won't work with language constructs such as echo
316+
// and print, so these are replaced with print_r.
317+
if (in_array(strtolower($error_callback), ['echo', 'print'])) {
318+
$error_callback = 'print_r';
319+
}
319320

320-
if (function_exists($error_callback)) {
321+
if (function_exists($error_callback)) {
322+
$this->_error_callback = $error_callback;
323+
}
324+
} else {
321325
$this->_error_callback = $error_callback;
322326
}
323327
}

0 commit comments

Comments
 (0)