# [RFC]: Change Default mysqli Error Mode

- Thread: https://externals.io/message/112947
- Original archive: https://news-web.php.net/php.internals/112947
- Started by Kamil Tekiela on 2021-01-20T23:04:36+00:00
- Messages: 38
- RFC: Change Default mysqli Error Mode (Implemented (PHP 8.1)) — https://externals.io/rfc/mysqli_default_errmode.md
- RFC: Concepts to improve mysqli extension (Inactive) — https://externals.io/rfc/improve_mysqli.md
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/112947.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #112947 — Kamil Tekiela — 2021-01-20T23:04:36+00:00

URL: https://externals.io/message/112947#112947

Hi Internals,

Following my earlier announcement in https://wiki.php.net/rfc/improve_mysqli
I decided to submit a dedicated RFC for the first proposal.

This RFC proposes to change the default mysqli error reporting mode to
exception mode. This change follows the same change in PDO. The RFC can be
found here https://wiki.php.net/rfc/mysqli_default_errmode

Kind Regards,
Kamil Tekiela

---

## #112956 — Larry Garfield — 2021-01-21T21:10:52+00:00

URL: https://externals.io/message/112947#112956 · In reply to: #112947

> Hi Internals,
> 
> Following my earlier announcement in https://wiki.php.net/rfc/improve_mysqli
> I decided to submit a dedicated RFC for the first proposal.
> 
> This RFC proposes to change the default mysqli error reporting mode to
> exception mode. This change follows the same change in PDO. The RFC can be
> found here https://wiki.php.net/rfc/mysqli_default_errmode
> 
> Kind Regards,
> Kamil Tekiela

Consistency FTW.  +1

--Larry Garfield

---

## #112958 — bjorn.x.larsson@telia.com — 2021-01-21T21:51:24+00:00

URL: https://externals.io/message/112947#112958 · In reply to: #112947

Den 2021-01-21 kl. 00:04, skrev Kamil Tekiela:
> Hi Internals,
> 
> Following my earlier announcement in https://wiki.php.net/rfc/improve_mysqli
> I decided to submit a dedicated RFC for the first proposal.
> 
> This RFC proposes to change the default mysqli error reporting mode to
> exception mode. This change follows the same change in PDO. The RFC can be
> found here https://wiki.php.net/rfc/mysqli_default_errmode
> 
> Kind Regards,
> Kamil Tekiela
> 

If I understand this correctly, does it imply that a lot of
legacy code that works today, will not work any longer and
needs to change? Like:
if ("mysqlierror") {
	"error handling"
}

If so I think that like in other RFC's an investigation should
be done on how much code that is affected to assess BC impact.

Btw, I liked your proposal on how to improve prepared statements
in mysqli a lot!

Regards //Björn Larsson

---

## #112961 — Kamil Tekiela — 2021-01-21T22:46:20+00:00

URL: https://externals.io/message/112947#112961 · In reply to: #112958

On Thu, 21 Jan 2021 at 21:51, Björn Larsson <bjorn.x.larsson@telia.com>
wrote:

> If I understand this correctly, does it imply that a lot of
> legacy code that works today, will not work any longer and
> needs to change? Like:
> if ("mysqlierror") {
>         "error handling"
> }
>
> If so I think that like in other RFC's an investigation should
> be done on how much code that is affected to assess BC impact.
>

The code will still work as it did before, but if there is an error then an
exception will be thrown. This means that by default the custom error
handlers will become redundant. Generally, this should not be a problem,
but I can imagine that some projects heavily rely upon the manual error
checking.

Among the popular PHP projects that I know of, only CodeIgniter and
WordPress still use mysqli.
CI does offer PDO as an option but due to legacy reasons, many people still
chose mysqli. However, they already use the exception mode.
https://github.com/codeigniter4/CodeIgniter4/blob/d5673f4376dc981196607bc159368bee9990033c/system/Database/MySQLi/Connection.php#L94
WordPress ... the black sheep of PHP ... uses mysqli with a fallback to
mysql_* API. They use manual error handling, which would be replaced by
normal exceptions unless they silence it. They should modernize their
codebase at some point as they can't cling on to the past forever. For the
moment if they want to continue using manual error checking then they need
to explicitly disable mysqli errors without relying on the default setting.
That is only 1 additional line of code. This would be the same as what I
have done in PHP internal test cases. I don't see any problems there.

In fact, I don't really see this as a major breaking change. If any project
really needs the mysqli errors silenced then they can just set the error
mode back to OFF. The change is aimed at new users, not existing projects.
Silenced error reporting was a source of confusion for plenty of beginners
who were unaware of the setting.

Kind Regards,
Kamil Tekiela

---

## #112965 — BohwaZ — 2021-01-22T16:16:17+00:00

URL: https://externals.io/message/112947#112965 · In reply to: #112956

We should do the same with SQLite3 extension.

---

## #112980 — Nikita Popov — 2021-01-25T10:03:35+00:00

URL: https://externals.io/message/112947#112980 · In reply to: #112947

> Hi Internals,
>
> Following my earlier announcement in
> https://wiki.php.net/rfc/improve_mysqli
> I decided to submit a dedicated RFC for the first proposal.
>
> This RFC proposes to change the default mysqli error reporting mode to
> exception mode. This change follows the same change in PDO. The RFC can be
> found here https://wiki.php.net/rfc/mysqli_default_errmode
>
> Kind Regards,
> Kamil Tekiela
>

Fully support this proposal. Throwing exceptions is the right default, it
matches what PDO does, and restoring the old behavior is one line of code.

Regards,
Nikita

---

## #112985 — Christian Schneider — 2021-01-25T15:41:17+00:00

URL: https://externals.io/message/112947#112985 · In reply to: #112961

Am 21.01.2021 um 23:46 schrieb Kamil Tekiela <tekiela246@gmail.com>:
> In fact, I don't really see this as a major breaking change. If any project
> really needs the mysqli errors silenced then they can just set the error
> mode back to OFF. The change is aimed at new users, not existing projects.
> Silenced error reporting was a source of confusion for plenty of beginners
> who were unaware of the setting.


As this definitely is a BC (applications stop running) I think we should go through a phase were it throws a warning instead of aborting, i.e. changing it to
	mysqli_report(MYSQLI_REPORT_ERROR);
first and change it to throw an exception after a grace period.

This would be in line with most other newly introduced exceptions for the default configuration.
Plus this would most certainly help people who host other people's websites who want to upgrade to PHP 8.x.

PS: IMHO The same should be (retroactively) done with `round()` and friends!

- Chris

---

## #112986 — G. P. B. — 2021-01-25T15:59:18+00:00

URL: https://externals.io/message/112947#112986 · In reply to: #112985

On Mon, 25 Jan 2021 at 15:41, Christian Schneider <cschneid@cschneid.com>
wrote:

> Am 21.01.2021 um 23:46 schrieb Kamil Tekiela <tekiela246@gmail.com>:
> > […]
> project
> > […]
> projects.
> > […]
> beginners
> > […]
>
>
> As this definitely is a BC (applications stop running) I think we should
> go through a phase were it throws a warning instead of aborting, i.e.
> changing it to
>         mysqli_report(MYSQLI_REPORT_ERROR);
> first and change it to throw an exception after a grace period.
>
> This would be in line with most other newly introduced exceptions for the
> default configuration.
> Plus this would most certainly help people who host other people's
> websites who want to upgrade to PHP 8.x.
>
> PS: IMHO The same should be (retroactively) done with `round()` and friends!
>
> - Chris
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>
The BC break is totally minimal as it's a one line of code that needs to be
added (and for all intent and purposes should already be done).

Moreover, I'd rather we get rid of the warning modes all together as they
make the least sense to me.
Either you're handling the failures explicitly anyway and you use the
silent mode, or you don't and want it to throw with the exception mode.
The warning mode is literally the worst of both worlds, it doesn't fail on
failure so you need to check for failure manually,
and you need to suppress the warnings because otherwise you get false
negatives.

Best regards,

George P. Banyard

---

## #112987 — Benjamin Morel — 2021-01-25T16:10:10+00:00

URL: https://externals.io/message/112947#112987 · In reply to: #112986

>
> Moreover, I'd rather we get rid of the warning modes all together as they
> make the least sense to me.
> Either you're handling the failures explicitly anyway and you use the
> silent mode, or you don't and want it to throw with the exception mode.
> The warning mode is literally the worst of both worlds, it doesn't fail on
> failure so you need to check for failure manually,
> and you need to suppress the warnings because otherwise you get false
> negatives.
>
> Best regards,
>
> George P. Banyard
>

I'd just like to say amen to that.

Please move as much code as possible to throwing exceptions, and get rid of
warnings. Most of the time when a warning is thrown in PHP, what you
actually want is to deal with it, or stop execution.

- Benjamin

---

## #112988 — Christian Schneider — 2021-01-25T16:25:38+00:00

URL: https://externals.io/message/112947#112988 · In reply to: #112986

Am 25.01.2021 um 16:59 schrieb G. P. B. <george.banyard@gmail.com>:
> The BC break is totally minimal as it's a one line of code that needs to be added (and for all intent and purposes should already be done).

That does not change the fact that it is a BC break which should be treated accordingly.

You are basically advocating people should add mysqli_report(MYSQLI_REPORT_OFF) to their setup which will totally defeat the purpose of the change.
Or (probably more what you have in mind) that they should add mysqli_report(MYSQLI_REPORT_ERROR) now (to prepare for the change) and switch to `MYSQLI_REPORT_ERROR` | `MYSQLI_REPORT_STRICT` later once they know they are ready.
And this is exactly what I think should be done by the PHP default so people don't have to go through this manually.

> Moreover, I'd rather we get rid of the warning modes all together as they make the least sense to me.
> Either you're handling the failures explicitly anyway and you use the silent mode, or you don't and want it to throw with the exception mode.

This is where you are missing a key component: I want to go through a phase where I will notice parts where manual error handling (or exception handling after the change) is missing without having my application abort. This is what warnings are good for.

To some of us this is a very valuable step when upgrading.

- Chris

---

## #112991 — G. P. B. — 2021-01-25T17:22:12+00:00

URL: https://externals.io/message/112947#112991 · In reply to: #112988

On Mon, 25 Jan 2021 at 16:25, Christian Schneider <cschneid@cschneid.com>
wrote:

> Am 25.01.2021 um 16:59 schrieb G. P. B. <george.banyard@gmail.com>:
> > […]
> be added (and for all intent and purposes should already be done).
>
> That does not change the fact that it is a BC break which should be
> treated accordingly.
>
> You are basically advocating people should add
> mysqli_report(MYSQLI_REPORT_OFF) to their setup which will totally defeat
> the purpose of the change.
> Or (probably more what you have in mind) that they should add
> mysqli_report(MYSQLI_REPORT_ERROR) now (to prepare for the change) and
> switch to `MYSQLI_REPORT_ERROR` | `MYSQLI_REPORT_STRICT` later once they know
> they are ready.
> And this is exactly what I think should be done by the PHP default so
> people don't have to go through this manually.
>
> > […]
> they make the least sense to me.
> > […]
> silent mode, or you don't and want it to throw with the exception mode.
>
> This is where you are missing a key component: I want to go through a
> phase where I will notice parts where manual error handling (or exception
> handling after the change) is missing without having my application abort.
> This is what warnings are good for.
>
> To some of us this is a very valuable step when upgrading.
>
> - Chris
>

I've never said there is no BC break, and frankly this change (and other
similar ones) should probably have been done in PHP 8 at the same time with
PDO.

And yes I'm basically advocating for people to add
mysqli_report(MYSQLI_REPORT_ERROR) (or even mysqli_report(MYSQLI_REPORT_OFF)
if they fancy) to their setup, I'm even advocating for them to do it *right
now* such that they can catch anything ahead of time.
Moreover, this proposal does not prevent you from using the warning mode
instead of jumping to exceptions directly, the key point is that you need
to specify it, and I personally believe that having the warning mode as the
*default* mode is the worst choice for the reasons I mentioned previously.
The removal of the warning modes is completely orthogonal to this proposal,
and I agree it is a very useful tool for transitioning to the exception
mode, but this transition can already be done in PHP 5, 7 and 8.

The grace period for completing this transition is from whenever you want
to whenever, if ever, the warning mode gets deprecated and removed.

On the note that a one line code change is not a good enough justification
for saner defaults, I don't know what to say.
At worst you need to find all usages of a connection start and add the line
to downgrade the error reporting (even to silence if too many warnings are
emitted).
I don't see what testing needs to be done, you're reverting to the previous
state which supposedly is already working.

Best regards,

George P. Banyard

---

## #112992 — Christian Schneider — 2021-01-25T17:33:23+00:00

URL: https://externals.io/message/112947#112992 · In reply to: #112991

Am 25.01.2021 um 18:22 schrieb G. P. B. <george.banyard@gmail.com>:
> And yes I'm basically advocating for people to add mysqli_report(MYSQLI_REPORT_ERROR) (or even mysqli_report(MYSQLI_REPORT_OFF) if they fancy) to their setup, I'm even advocating for them to do it right now such that they can catch anything ahead of time.

Defaults matter. Most people will *not* do this step and their code will fail on upgrade.

> Moreover, this proposal does not prevent you from using the warning mode instead of jumping to exceptions directly, the key point is that you need to specify it, and I personally believe that having the warning mode as the default mode is the worst choice for the reasons I mentioned previously.

Agree to disagree.

If I have the choice to make the smoothen the transition centrally with PHP defaults or rely on each user to do it manually by proactively setting warning modes I prefer the defaults way.

Remember: I am not advocating staying in the warning mode, I'm just seeing it as a useful intermediate step for legacy stuff we want to fix.

- Chris

---

## #112994 — drealecs@gmail.com — 2021-01-26T06:57:21+00:00

URL: https://externals.io/message/112947#112994 · In reply to: #112992

On Mon, Jan 25, 2021 at 7:33 PM Christian Schneider <cschneid@cschneid.com>
wrote:

> Am 25.01.2021 um 18:22 schrieb G. P. B. <george.banyard@gmail.com>:
> > […]
> mysqli_report(MYSQLI_REPORT_ERROR) (or even
> mysqli_report(MYSQLI_REPORT_OFF) if they fancy) to their setup, I'm even
> advocating for them to do it right now such that they can catch anything
> ahead of time.
>
> Defaults matter. Most people will *not* do this step and their code will
> fail on upgrade.
>
> > […]
> instead of jumping to exceptions directly, the key point is that you need
> to specify it, and I personally believe that having the warning mode as the
> default mode is the worst choice for the reasons I mentioned previously.
>
> Agree to disagree.
>
> If I have the choice to make the smoothen the transition centrally with
> PHP defaults or rely on each user to do it manually by proactively setting
> warning modes I prefer the defaults way.
>
> Remember: I am not advocating staying in the warning mode, I'm just seeing
> it as a useful intermediate step for legacy stuff we want to fix.
>
> - Chris
>
>
  Hi Chris,

I think PHP is far from targeting a zero cost on version upgrade for
projects.
There will be other parts that will require testing, whatever you do.
Trying to optimize this to reduce the 1 line quick fix that could be easily
read in the documentation at https://www.php.net/manual/en/migration81.php
sounds to me like we're trying too hard to reduce this cost, ignoring
others. Other technical costs would be to not switch earlier to new
exception mode as long as the default will cover the cases.

I am thinking about this with a legacy system in mind that is long due on
exception handling for the database layer. I know that having exceptions by
default would spark an interest in developers' minds to do this change
sooner rather than later because they will feel the default is the
recommended way. Due to bandwidth allocation, they might add the line
there, but a task will be created to fix it in the next few months, maybe a
year.

There will be a cost of upgrading. New scenarios and tests that might not
even exist currently, negative flow scenarios.

Regards,
Alex

---

## #112995 — Christian Schneider — 2021-01-26T07:42:31+00:00

URL: https://externals.io/message/112947#112995 · In reply to: #112994

Am 26.01.2021 um 07:57 schrieb Alexandru Pătrănescu <drealecs@gmail.com>:
> There will be other parts that will require testing, whatever you do. Trying to optimize this to reduce the 1 line quick fix that could be easily read in the documentation at https://www.php.net/manual/en/migration81.php <https://www.php.net/manual/en/migration81.php> sounds to me like we're trying too hard to reduce this cost, ignoring others.

The migration guides are already getting quite long, just have a look at https://www.php.net/manual/de/migration80.incompatible.php <https://www.php.net/manual/de/migration80.incompatible.php>
"Just one more line" can add up and that's why I want to be able to proactively fix my code, not fixing it at the time of migration.

If the error mode would be changed to warnings instead of exceptions first then every developer interested in best practices could and would already adapt their code. But they could do it gradually without the disruption of hard fails looming over them.

I just think giving developers a warning period (per default, not opt-in) is the right thing to do for BC breaks. [ Did I mention `round()`? ;-) ]

I start to sound like a broken record, I'll leave it at that,
- Chris

---

## #112997 — Kamil Tekiela — 2021-01-26T15:57:41+00:00

URL: https://externals.io/message/112947#112997 · In reply to: #112995

I would like to say that I completely agree with George. The BC is minimal.
We are not introducing any new functionality or removing any either. We are
just changing a default setting that was always there. The only code that
would be affected is the one that is currently relying on the default
setting. Most of the mysqli code should already have the setting
enabled/disabled explicitly. If your current code has mysqli error
reporting disabled then nothing will change for you. If your current code
has mysqli error reporting enabled then nothing will change for you. It
will only change in the code that doesn't have it enabled/disabled yet.
Such a project would need to decide whether to enable it or disable it.
This can be done even now, and it should be done now, regardless of whether
this RFC is accepted or not.

> Or (probably more what you have in mind) that they should add
mysqli_report(MYSQLI_REPORT_ERROR) now (to prepare for the change) and
switch to `MYSQLI_REPORT_ERROR` | `MYSQLI_REPORT_STRICT` later once they know
they are ready.

IMHO the warning mode is useless as it doesn't stop the code execution
automatically but still throws an error. You either enable error reporting
in the form of exceptions, or you keep it silenced. I believe changing the
default mode to warning mode makes no sense.
Bear in mind that you can do it right now. There's no need for you to wait
for PHP 8.1 to see the change. You can decide on the error reporting mode
right now. However, I fail to see how mysqli_report(MYSQLI_REPORT_ERROR)
could help in migrating the code. As long as your code doesn't have any
errors, the error reporting mode will make no difference.

> This is where you are missing a key component: I want to go through a
phase where I will notice parts where manual error handling (or exception
handling after the change) is missing without having my application abort.
This is what warnings are good for.

Enabling warning mode will not help you in finding places where you are
missing manual error handling. That is the whole point. Manual error
handling means that you have to do it manually. When you enable warnings or
exceptions then manual error handling is already useless. If you think that
your code is missing some manual error handling then enabling
warning/exception mode will not reveal to you where these places are. You
have to go line by line through your code and everwhere you see a mysqli
method/function call you have to add manual error handling.

I want to make things straight. Changing the default error mode is not
forcing anyone to use exception mode out of the sudden. You can still
continue to use whichever mode you are using right now. The change is aimed
at people who start their new projects with PHP 8.1 and want to learn
mysqli.

> I don't see what testing needs to be done, you're reverting to the
previous state which supposedly is already working.

I also do not know what kind of additional testing would be required. The
functionality stays the same. A project code should remain the same unless
its maintainers decide to refactor it. All that is needed is to make sure
that the project has the correct mode enabled and does not rely on the
default setting.

---

## #113001 — Nikita Popov — 2021-01-27T13:34:43+00:00

URL: https://externals.io/message/112947#113001 · In reply to: #112995

On Tue, Jan 26, 2021 at 8:42 AM Christian Schneider <cschneid@cschneid.com>
wrote:

> Am 26.01.2021 um 07:57 schrieb Alexandru Pătrănescu <drealecs@gmail.com>:
> > […]
> Trying to optimize this to reduce the 1 line quick fix that could be easily
> read in the documentation at https://www.php.net/manual/en/migration81.php
> <https://www.php.net/manual/en/migration81.php> sounds to me like we're
> trying too hard to reduce this cost, ignoring others.
>
> The migration guides are already getting quite long, just have a look at
> https://www.php.net/manual/de/migration80.incompatible.php <
> https://www.php.net/manual/de/migration80.incompatible.php>
> "Just one more line" can add up and that's why I want to be able to
> proactively fix my code, not fixing it at the time of migration.
>
> If the error mode would be changed to warnings instead of exceptions first
> then every developer interested in best practices could and would already
> adapt their code. But they could do it gradually without the disruption of
> hard fails looming over them.
>
> I just think giving developers a warning period (per default, not opt-in)
> is the right thing to do for BC breaks. [ Did I mention `round()`? ;-) ]
>
> I start to sound like a broken record, I'll leave it at that,
> - Chris
>

I think if you wanted to introduce an additional diagnostic step, the way
to go about it would be to issue a deprecation warning when creating a
connection without `mysqli_report()` having been explicitly called
beforehand. As others have said, the warning mode is pretty much entirely
useless, and what you really want (presumably) is to know about the places
where you need to explicitly call `mysqli_report()` to preserve the old
behavior (or explicitly switch to the new one).

Regards,
Nikita

---

## #113002 — Sebastian Bergmann — 2021-01-27T14:17:43+00:00

URL: https://externals.io/message/112947#113002 · In reply to: #112980

Am 25.01.2021 um 11:03 schrieb Nikita Popov:
> Fully support this proposal. Throwing exceptions is the right default, it
> matches what PDO does, and restoring the old behavior is one line of code.

I second that emotion.

---

## #113003 — Christian Schneider — 2021-01-27T14:35:04+00:00

URL: https://externals.io/message/112947#113003 · In reply to: #113001

Am 27.01.2021 um 14:34 schrieb Nikita Popov <nikita.ppv@gmail.com>:
> I think if you wanted to introduce an additional diagnostic step, the way to go about it would be to issue a deprecation warning when creating a connection without `mysqli_report()` having been explicitly called beforehand.

Wouldn't this mean everybody would add `mysqli_report()` to their code?
And wouldn't this render the default of `mysqli_report()` entirely useless?
Or is your idea that at a later stage you then want to create a warning for manual `mysqli_report()` calls?

> As others have said, the warning mode is pretty much entirely useless, and what you really want (presumably) is to know about the places where you need to explicitly call `mysqli_report()` to preserve the old behavior (or explicitly switch to the new one).

No, I want to know if I have any code which needs fixing so I can see how I want to change those places e.g. a duplicate key from INSERT to REPLACE or whatever the correct fix is. Without the code aborting.

Yes, individual developers can switch on mysqli_report(MYSQLI_REPORT_ERROR) *now* to get this behavior but I still think this makes more sense as a default. Otherwise the temptation is big to just add a global mysqli_report(MYSQLI_REPORT_OFF) everywhere just in case.

- Chris

---

## #113004 — Nikita Popov — 2021-01-27T14:48:24+00:00

URL: https://externals.io/message/112947#113004 · In reply to: #113003

On Wed, Jan 27, 2021 at 3:35 PM Christian Schneider <cschneid@cschneid.com>
wrote:

> Am 27.01.2021 um 14:34 schrieb Nikita Popov <nikita.ppv@gmail.com>:
> > […]
> way to go about it would be to issue a deprecation warning when creating a
> connection without `mysqli_report()` having been explicitly called beforehand.
>
> Wouldn't this mean everybody would add `mysqli_report()` to their code?
> And wouldn't this render the default of `mysqli_report()` entirely useless?
> Or is your idea that at a later stage you then want to create a warning
> for manual `mysqli_report()` calls?
>

Yes, that would render a call to `mysqli_report()` required until the version
where the default was switched, and the requirement went away. A call to
 `mysqli_report()` is already required if you use exception-based error
handling. The deprecation would force those people who use manual error
handling by default to make an explicit choice.


> > […]
> and what you really want (presumably) is to know about the places where you
> need to explicitly call `mysqli_report()` to preserve the old behavior (or
> explicitly switch to the new one).
>
> No, I want to know if I have any code which needs fixing so I can see how
> I want to change those places e.g. a duplicate key from INSERT to REPLACE
> or whatever the correct fix is. Without the code aborting.
>

Okay, I think I now get what you want. My line of thinking was that people
who use manual error handling likely just want to keep doing that, and
should opt-in to it once the default changes. You apparently want them to
switch to use exceptions, in which case the warning mode might indeed be
useful to identify cases where "expected" errors occur.

However, I don't think this has much to do with the proposal at hand. If
someone wants to migrate their code to use exceptions, that's of course
great, but they could do that any time, regardless of what the default is.
They could have done that ten years ago, and they could do it in ten years.

This proposal is only about switching the default, which is why I mentioned
the possibility of diagnosing cases where it may be observable. That said,
I don't think doing so would actually be particularly useful in practice.
And it wouldn't even address your particular concern. As such, I think the
RFC should stick with the original proposal of simply flipping the default
directly.

Regards,
Nikita

---

## #113005 — Kamil Tekiela — 2021-01-27T15:07:33+00:00

URL: https://externals.io/message/112947#113005 · In reply to: #113003

>
> Wouldn't this mean everybody would add `mysqli_report()` to their code?

That is the idea. That is what everyone should already have in their
codebase.

  And wouldn't this render the default of `mysqli_report()` entirely useless?

I'm sorry, but I don't follow the train of thought? Why would it make that
useless? You must set the correct error reporting mode anyway and that
function helps in doing so.

  Or is your idea that at a later stage you then want to create a warning
> for manual `mysqli_report()` calls?

What are manual `mysqli_report()` calls? You either have that line in your
code or you don't. The idea that Nikita suggested is to meet your concerns.
The only way to figure out if your code needs an adjustment is to have a
warning emitted from any mysqli connect methods if you have not called
mysqli_report before. It would inform users that they are missing the
setting.

  No, I want to know if I have any code which needs fixing so I can see how
> I want to change those places e.g. a duplicate key from INSERT to REPLACE
> or whatever the correct fix is. Without the code aborting.

You can do that right now. This proposal will not make it easier or more
difficult for you to do that. Just paste mysqli_report(MYSQLI_REPORT_ERROR)
before `mysqli_connect()` and PHP will generate a warning whenever your SQL
throws an error.

  Otherwise the temptation is big to just add a global
> mysqli_report(MYSQLI_REPORT_OFF) everywhere just in case.

I don't get what's wrong with that. This is literally what I said in the
RFC you can do if you don't want mysqli to report any errors. Whoever
doesn't want to see errors can use this line to silence them.
I would even make a counterpoint. If we set  `MYSQLI_REPORT_ERROR` as the
default then users will definitely silence errors and forget. The warning
mode is so useless and annoying that people will prefer to silence it
seeing no benefit to it. If we want this change to be useful then we should
make SQL errors report as exceptions by default.

Regarding Nikita's proposal: The compromise is reasonable, but this will
not be well-received by the community. Additional warnings will only make
things more confusing without providing outstanding benefits. If we want to
force people to set the error reporting mode that they want, then it would
be better to set a sensible default value and give a clear explanation in
the migration guide how to set it back to the previous value. Of course, I
don't hate Nikita's proposal and I might say I even like it a little bit,
but only in connection with exception mode as the default value. This way
users will not be surprised by an exception if it happens that they forget
to silence. But I would prefer that everyone embraced exceptions.

---

## #113006 — bjorn.x.larsson@telia.com — 2021-01-27T16:13:05+00:00

URL: https://externals.io/message/112947#113006 · In reply to: #113005

Den 2021-01-27 kl. 16:07, skrev Kamil Tekiela:
> > […]
> 
> That is the idea. That is what everyone should already have in their
> codebase.
> 
>    And wouldn't this render the default of `mysqli_report()` entirely useless?
> 
> I'm sorry, but I don't follow the train of thought? Why would it make that
> useless? You must set the correct error reporting mode anyway and that
> function helps in doing so.
> 
>    Or is your idea that at a later stage you then want to create a warning
> > […]
> 
> What are manual `mysqli_report()` calls? You either have that line in your
> code or you don't. The idea that Nikita suggested is to meet your concerns.
> The only way to figure out if your code needs an adjustment is to have a
> warning emitted from any mysqli connect methods if you have not called
> mysqli_report before. It would inform users that they are missing the
> setting.
> 
>    No, I want to know if I have any code which needs fixing so I can see how
> > […]
> 
> You can do that right now. This proposal will not make it easier or more
> difficult for you to do that. Just paste mysqli_report(MYSQLI_REPORT_ERROR)
> before `mysqli_connect()` and PHP will generate a warning whenever your SQL
> throws an error.
> 
>    Otherwise the temptation is big to just add a global
> > […]
> 
> I don't get what's wrong with that. This is literally what I said in the
> RFC you can do if you don't want mysqli to report any errors. Whoever
> doesn't want to see errors can use this line to silence them.
> I would even make a counterpoint. If we set  `MYSQLI_REPORT_ERROR` as the
> default then users will definitely silence errors and forget. The warning
> mode is so useless and annoying that people will prefer to silence it
> seeing no benefit to it. If we want this change to be useful then we should
> make SQL errors report as exceptions by default.
> 
> Regarding Nikita's proposal: The compromise is reasonable, but this will
> not be well-received by the community. Additional warnings will only make
> things more confusing without providing outstanding benefits. If we want to
> force people to set the error reporting mode that they want, then it would
> be better to set a sensible default value and give a clear explanation in
> the migration guide how to set it back to the previous value. Of course, I
> don't hate Nikita's proposal and I might say I even like it a little bit,
> but only in connection with exception mode as the default value. This way
> users will not be surprised by an exception if it happens that they forget
> to silence. But I would prefer that everyone embraced exceptions.
> 
I'm missing a thing here when we talk about "your code". I mean on our 
site we have third party libraries. They can typically have a release 
schedule on a couple of releases each year. So all code is not up to
us to change. So how does this proposal adress that scenario when it's
not up to us to do the necessary changes? Is it e.g. a blocker to 
upgrade to PHP 8.1 with exceptions vs warnings until the library is updated?

As a side note I'm at the moment migrating our test site to PHP 8 and
the two most prominent hickups are located in a third party library: 
"Undefined array key" and "Attempt to read property "value" on null"
which are warnings. Not sure how it would have been with these as
exceptions, e.g. would the test site stop running and thereby stop
testing of other parts.

And as I have said earlier, I do like exceptions! It's the migration
aspect I'm wondering about...

r//Björn L

---

## #113008 — bjorn.x.larsson@telia.com — 2021-01-27T16:39:02+00:00

URL: https://externals.io/message/112947#113008 · In reply to: #113006

Den 2021-01-27 kl. 17:13, skrev Björn Larsson:
> Den 2021-01-27 kl. 16:07, skrev Kamil Tekiela:
> > […]
> I'm missing a thing here when we talk about "your code". I mean on our 
> site
> we have third party libraries. They can typically have a release 
> schedule on
> a couple of releases each year. So all code is not up to us to change. 
> So how
> does this proposal adress that scenario when it's  not up to us to do the
> necessary changes? Is it e.g. a blocker to upgrade to PHP 8.1 with
> exceptions vs warnings until the library is updated?
>
> As a side note I'm at the moment migrating our test site to PHP 8 and
> the two most prominent hickups are located in a third party library:
> "Undefined array key" and "Attempt to read property "value" on null"
> which are warnings. Not sure how it would have been with these as
> exceptions, e.g. would the test site stop running and thereby stop
> testing of other parts.
>
> And as I have said earlier, I do like exceptions! It's the migration
> aspect I'm wondering about...
>
> r//Björn L

PS And sorry for the lousy formatting in earlier response.

---

## #113012 — Kamil Tekiela — 2021-01-28T00:31:19+00:00

URL: https://externals.io/message/112947#113012 · In reply to: #113006

>
> I'm missing a thing here when we talk about "your code". I mean on our
> site we have third party libraries. They can typically have a release
> schedule on a couple of releases each year. So all code is not up to
> us to change. So how does this proposal adress that scenario when it's
> not up to us to do the necessary changes? Is it e.g. a blocker to
> upgrade to PHP 8.1 with exceptions vs warnings until the library is
> updated?
>
> As a side note I'm at the moment migrating our test site to PHP 8 and
> the two most prominent hickups are located in a third party library:
> "Undefined array key" and "Attempt to read property "value" on null"
> which are warnings. Not sure how it would have been with these as
> exceptions, e.g. would the test site stop running and thereby stop
> testing of other parts.
>
> And as I have said earlier, I do like exceptions! It's the migration
> aspect I'm wondering about...
>
> r//Björn L
>

This is a valid concern. I have thought about it for a while and I think
that we should handle this the same way we did with PDO error mode change.
We don't do anything special.

I really don't see a way that we could make a smoother upgrading
experience. For users that avail of old libraries the onus is on them to
check the library's compatibility with the new PHP version. Ideally, the
change should have been made in PHP 8.0 where it would be more justifiable
to change a default setting.

The good thing about mysqli error reporting compared to PDO is that the
setting is global. If the library you are using is abandoned or you can't
wait for the library to be updated then you can set the error reporting
level in your own code. The only problem comes when you want to mix both
modes in the same code, but that is a huge code smell anyway. This means
that this change is not a blocker for the upgrade.

I think the proposal is good to be implemented in PHP 8.1 as it is now. But
if anyone thinks otherwise or has any ideas on how to improve I would
gladly take it into consideration. If there is any way that we could make
the migration smoother then it would be great.

Kamil

---

## #113014 — bjorn.x.larsson@telia.com — 2021-01-28T15:37:35+00:00

URL: https://externals.io/message/112947#113014 · In reply to: #113012

Den 2021-01-28 kl. 01:31, skrev Kamil Tekiela:
>
>     I'm missing a thing here when we talk about "your code". I mean on
>     our
>     site we have third party libraries. They can typically have a release
>     schedule on a couple of releases each year. So all code is not up to
>     us to change. So how does this proposal adress that scenario when it's
>     not up to us to do the necessary changes? Is it e.g. a blocker to
>     upgrade to PHP 8.1 with exceptions vs warnings until the library
>     is updated?
>
>     As a side note I'm at the moment migrating our test site to PHP 8 and
>     the two most prominent hickups are located in a third party library:
>     "Undefined array key" and "Attempt to read property "value" on null"
>     which are warnings. Not sure how it would have been with these as
>     exceptions, e.g. would the test site stop running and thereby stop
>     testing of other parts.
>
>     And as I have said earlier, I do like exceptions! It's the migration
>     aspect I'm wondering about...
>
>     r//Björn L
>
>
> This is a valid concern. I have thought about it for a while and I 
> think that we should handle this the same way we did with PDO error 
> mode change. We don't do anything special.
>
> I really don't see a way that we could make a smoother upgrading 
> experience. For users that avail of old libraries the onus is on them 
> to check the library's compatibility with the new PHP version. 
> Ideally, the change should have been made in PHP 8.0 where it would be 
> more justifiable to change a default setting.
>
> The good thing about mysqli error reporting compared to PDO is that 
> the setting is global. If the library you are using is abandoned or 
> you can't wait for the library to be updated then you can set the 
> error reporting level in your own code. The only problem comes when 
> you want to mix both modes in the same code, but that is a huge code 
> smell anyway. This means that this change is not a blocker for the 
> upgrade.
>
> I think the proposal is good to be implemented in PHP 8.1 as it is 
> now. But if anyone thinks otherwise or has any ideas on how to improve 
> I would gladly take it into consideration. If there is any way that we 
> could make the migration smoother then it would be great.
>
> Kamil

Yes, this proposal would probably have been close to a no-brainer in
PHP 8.0.

I think the RFC would benefit on expanding on some of the key issues
that has been discussed, e.g. the clarification above about migration
aspects.

/r//Björn L/

---

## #113033 — Kamil Tekiela — 2021-01-31T18:20:50+00:00

URL: https://externals.io/message/112947#113033 · In reply to: #113014

Hi All,

I have updated the RFC at https://wiki.php.net/rfc/mysqli_default_errmode
and provided FAQ with the aim to explain your concerns as best as I could.
I have also added a section that explains all mysqli error reporting modes.

Best regards,
Kamil

---

Next page: https://externals.io/message/112947.md?page=2
