Skip to content

Commit de78f65

Browse files
authored
Merge pull request #4 from jr-cologne/jr_swap-params-initErrorHandler()
Swap order of parameters of initErrorHandler()
2 parents cf4e49f + 88927e4 commit de78f65

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

DB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DB {
1313
protected $error = [ 'code' => 0, 'msg' => null ];
1414

1515
// initialize error handler / define configs for error handling
16-
public static function initErrorHandler(array $error_types=[], string $env='production') {
16+
public static function initErrorHandler(string $env='production', array $error_types=[]) {
1717
self::$env = $env;
1818

1919
if ($error_types == []) {

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ Default:
303303

304304
Besides from that you can freely change the error messages to your own liking.
305305

306-
To change the config of the error handling, you must call the static method `initErrorHandler(array $error_types=[], string $env='production')`, which will basically set your specified configs, **before** you are instantiating the class.
306+
To change the config of the error handling, you must call the static method `initErrorHandler(string $env='production', array $error_types=[])`, which will basically set your specified configs, **before** you are instantiating the class.
307307

308308
Example:
309309
```php
310310
DB::initErrorHandler(
311+
'production',
311312
[
312313
0 => 'success',
313314
1 => 'Sorry, the connection to the database is failed!',
@@ -321,15 +322,6 @@ DB::initErrorHandler(
321322

322323
Always make sure to pass in the whole array, e.g. not just error 2 and 5, because then only error 2 and 5 will exist.
323324

324-
In case you don't want to change the messages, but you would like to switch the environment, you have to pass in an empty array as the first argument like that:
325-
326-
```php
327-
DB::initErrorHandler(
328-
[],
329-
'development'
330-
);
331-
```
332-
333325
### Check for Errors (`error()`)
334326
In case you want to know if an error occured, you can simply call the method `error()` and it will return you `true` or `false` based on the fact whether there is an error or not.
335327

example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require_once('DB.php');
33

44
DB::initErrorHandler(
5+
'production',
56
[
67
0 => 'success',
78
1 => 'Sorry, the connection to the database is failed!',

0 commit comments

Comments
 (0)