On 12 Feb 2021, at 15:17, Christian Schneider <cschn...@cschneid.com> wrote:
> 
> Am 12.02.2021 um 15:30 schrieb Craig Francis <cr...@craigfrancis.co.uk>:
>> Switching the default from `OFF` to `ERROR` to `ERROR | STRICT` isn't an 
>> obvious step, as that still means you're still having a single step to 
>> change from error reporting to exceptions.
> 
> It is the usual step for (almost) all BC breaking changes in PHP: Warn first 
> (leaving time to find and adapt code), explode later.
> The question is not *if* the change has to be made (or how big it is) but 
> *when* (and how to find places to be changed).



Oh, I completely agree, but Nikita's solution gives a better warning about the 
change to using exceptions.

As in, it would warn that mysqli_report() needs to be used, to specify the 
reporting mode you want, before the default changes.

Going via `MYSQLI_REPORT_ERROR` first, well, it doesn't exactly warn about that 
(it kinda moves forward a bit, but it doesn't warn that exceptions will be the 
new default in 8.2).

Craig





I know you know this already, I'm only including this as a note to self, to 
check how these changes will affect this example code:

    $db = new mysqli('localhost', 'user', 'password', 'db');
    $result = $db->query('SELECT COUNT(id) FROM invalid_table');
    if ($result) {
        print_r(mysqli_fetch_assoc($result));
    } else {
        print_r('Error');
    }

Currently this just prints 'Error'.

Step 1) Using `MYSQLI_REPORT_ERROR` would add a warning; and then continue to 
print 'Error' - it's not really that different, maybe more error messages are 
shown or logged, but it still works in the same way.

Step 2) Using `MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT` is the big-ish 
change, because it will now throw an exception, and the error (which ideally 
won't happen in the first place) needs to be handled in a completely different 
way.

That said, we are talking about what happens when something goes wrong, and 
generally speaking, that shouldn't happen on an already running system... which 
is why I'm fairly happy with the change that Kamil is proposing.

And I should note, maybe phpMyAdmin is an oddity here, because I will make 
typos, and those need to be handled properly, and, erm, phpMyAdmin doesn't 
currently use mysqli_report().

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to