Hi all,
A regular problem that new users run into is error handling with PDO.
The current default error mode for PDO is "silent". This leads to the
situation where code doesn't work and returns no obvious errors unless
PDO specific error handling code is explicitly added.
I would like to propose the default error mode be changed from PHP 8 as
I believe this would make PDO error handling much more intuitive for new
developers, preventing the common "my code isn't working and I don't
know why" scenario that occurs.
While a BC break, I believe it's the type of change developers expect in
a major version and I don't believe that explicitly setting the error
mode for code bases that rely on the silent error mode is onerous - many
code bases are already explicitly setting the error mode already.
Given the way error handling has been / is heading in PHP, I would
suggest the default error mode should be exceptions, but I can forsee
arguments for using warnings instead ("less of a BC break" since code
would still continue unless a custom error handler causes an abort, so
closer to the behavior of "silent").
What are peoples views on making this change?
What do you think the new default be (and why)?
(I am aware this change will likely require an RFC)
AllenJB
Hi all,
A regular problem that new users run into is error handling with PDO.
The current default error mode for PDO is "silent". This leads to the
situation where code doesn't work and returns no obvious errors unless
PDO specific error handling code is explicitly added.I would like to propose the default error mode be changed from PHP 8 as
I believe this would make PDO error handling much more intuitive for new
developers, preventing the common "my code isn't working and I don't
know why" scenario that occurs.While a BC break, I believe it's the type of change developers expect in
a major version and I don't believe that explicitly setting the error
mode for code bases that rely on the silent error mode is onerous - many
code bases are already explicitly setting the error mode already.Given the way error handling has been / is heading in PHP, I would
suggest the default error mode should be exceptions, but I can forsee
arguments for using warnings instead ("less of a BC break" since code
would still continue unless a custom error handler causes an abort, so
closer to the behavior of "silent").What are peoples views on making this change?
What do you think the new default be (and why)?
(I am aware this change will likely require an RFC)
AllenJB
I see only two options:
-
Do nothing.
-
Move to Exceptions.
I've never used PDO and not set it to Exceptions, honestly. Adding more global error conditions to code is a terrible idea, so let's not do warnings. If your query breaks, you really shouldn't continue because your data is busted so your following code will fail ungracefully at best, or corrupt data at worst.
Changing a default like this seems a reasonably safe thing to do in a major, as long as it's still just as easy to switch back to silent mode for those who prefer to be explicit.
--Larry Garfield
Hi all,
A regular problem that new users run into is error handling with PDO.
The current default error mode for PDO is "silent". This leads to the
situation where code doesn't work and returns no obvious errors unless
PDO specific error handling code is explicitly added.I would like to propose the default error mode be changed from PHP 8 as
I believe this would make PDO error handling much more intuitive for new
developers, preventing the common "my code isn't working and I don't
know why" scenario that occurs.While a BC break, I believe it's the type of change developers expect in
a major version and I don't believe that explicitly setting the error
mode for code bases that rely on the silent error mode is onerous - many
code bases are already explicitly setting the error mode already.Given the way error handling has been / is heading in PHP, I would
suggest the default error mode should be exceptions, but I can forsee
arguments for using warnings instead ("less of a BC break" since code
would still continue unless a custom error handler causes an abort, so
closer to the behavior of "silent").What are peoples views on making this change?
What do you think the new default be (and why)?
(I am aware this change will likely require an RFC)
AllenJB
I see only two options:
Do nothing.
Move to Exceptions.
I've never used PDO and not set it to Exceptions, honestly. Adding more
global error conditions to code is a terrible idea, so let's not do
warnings. If your query breaks, you really shouldn't continue because your
data is busted so your following code will fail ungracefully at best, or
corrupt data at worst.Changing a default like this seems a reasonably safe thing to do in a
major, as long as it's still just as easy to switch back to silent mode for
those who prefer to be explicit.--Larry Garfield
--
Agreed this should be an all or nothing change.
Best regards
George P. Banyard
Hi,
What do you think the new default be (and why)?
(I am aware this change will likely require an RFC)
AllenJB
I see only two options:
Do nothing.
Move to Exceptions.
I've never used PDO and not set it to Exceptions, honestly. Adding more global error conditions to code is a terrible idea, so let's not do warnings. If your query breaks, you really shouldn't continue because your data is busted so your following code will fail ungracefully at best, or corrupt data at worst.
Changing a default like this seems a reasonably safe thing to do in a major, as long as it's still just as easy to switch back to silent mode for those who prefer to be explicit.
I agree defaulting to PDO::ERRMODE_EXCEPTION is a sensible change for PHP8.
Cheers
Matteo Beccati
Development & Consulting - http://www.beccati.com/
Am 19.03.2020 um 10:31 schrieb Matteo Beccati php@beccati.com:
What do you think the new default be (and why)?
(I am aware this change will likely require an RFC)
AllenJB
I see only two options:
Do nothing.
Move to Exceptions.
I've never used PDO and not set it to Exceptions, honestly. Adding more global error conditions to code is a terrible idea, so let's not do warnings. If your query breaks, you really shouldn't continue because your data is busted so your following code will fail ungracefully at best, or corrupt data at worst.
Changing a default like this seems a reasonably safe thing to do in a major, as long as it's still just as easy to switch back to silent mode for those who prefer to be explicit.
I agree defaulting to PDO::ERRMODE_EXCEPTION is a sensible change for PHP8.
I think this should go through a deprecation phase first as it is a BC break, no matter how easy to fix you think it is.
- Chris
Am 19.03.2020 um 10:31 schrieb Matteo Beccati php@beccati.com:
What do you think the new default be (and why)?
(I am aware this change will likely require an RFC)
AllenJB
I see only two options:
Do nothing.
Move to Exceptions.
I've never used PDO and not set it to Exceptions, honestly. Adding more global error conditions to code is a terrible idea, so let's not do warnings. If your query breaks, you really shouldn't continue because your data is busted so your following code will fail ungracefully at best, or corrupt data at worst.
Changing a default like this seems a reasonably safe thing to do in a major, as long as it's still just as easy to switch back to silent mode for those who prefer to be explicit.
I agree defaulting to PDO::ERRMODE_EXCEPTION is a sensible change for PHP8.
I think this should go through a deprecation phase first as it is a BC break, no matter how easy to fix you think it is.
As I understand it, the proposal is to change the default setting, not
to (eventually) remove any of the currently available modes. Are you
suggesting to deprecate using the default; in other words, require users
to explicitly set PDO::ATTR_ERRMODE?
--
Christoph M. Becker
Am 19.03.2020 um 10:31 schrieb Matteo Beccati php@beccati.com:
I agree defaulting to PDO::ERRMODE_EXCEPTION is a sensible change for PHP8.
I think this should go through a deprecation phase first as it is a BC break, no matter how easy to fix you think it is.
- Chris
To clarify: I'm not proposing the silent error mode be removed - it
would still exist and developers would be able to switch (back) to it
simply by explicitly setting the error mode when creating a PDO object.
How do you see that a deprecation would be implemented for this change?
A deprecation notice each time a PDO object is created without
explicitly setting the error mode?
Is this not just as disruptive to existing code as changing the default
error handling to warnings? For new users I can see it being more so:
Every time a new developer follows an older example they're going to be
asking about this deprecation message (or worse, changing
error_reporting or using @ to silence it!). Without a deprecation phase,
existing examples will continue to work (errors will just be reported
differently, but no in an unintuitive way in my opinion)
AllenJB