Re: [PHP-DEV] Changing default assertion mode to throw exceptions

This is only part of a thread. view whole thread
  110979
July 13, 2020 17:51 marcio.web2@gmail.com (Marcio Almada)
Hi!

> > Hello everyone, > > I'd like to change the default mode of assertion failures to throw. > The current default is to warn. In my opinion this is a bad strategy: > the engine asserted that something that is expected to be true is not, > so executing further is a bad idea. This leaves throwing or bailing > out. I think throwing an exception is better than bailing out, so > that's what I propose. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >
Couldn't agree more, but I always assumed this BC break could be too big before. Did you make any research on the impact already? Otherwise +1 Ty, Márcio
  111000
July 14, 2020 15:10 internals@lists.php.net ("Levi Morrison via internals")
On Mon, Jul 13, 2020 at 11:52 AM Marcio Almada web2@gmail.com> wrote:
> > I'd like to change the default mode of assertion failures to throw. > > The current default is to warn. In my opinion this is a bad strategy: > > the engine asserted that something that is expected to be true is not, > > so executing further is a bad idea. This leaves throwing or bailing > > out. I think throwing an exception is better than bailing out, so > > that's what I propose. > > Couldn't agree more, but I always assumed this BC break could be > too big before. Did you make any research on the impact already? > > Otherwise +1
Nikita put together a search of top packagist repositories to look for assert: https://gist.github.com/nikic/8311ee63c72573d514217456bf2df552 We can't generally know what their ini settings are, though. In my opinion this change is worth any backwards compatibility break as we are choosing the worst setting except for ignoring them altogether, and can be changed back to the previous value using an existing ini setting; we just need to put a note in the migrating guide.
  111003
July 14, 2020 16:19 theodorejb@outlook.com (Theodore Brown)
On Tue, July 14 2020 at 10:10 AM Levi Morrison wrote:

> On Mon, Jul 13, 2020 at 11:52 AM Marcio Almada web2@gmail.com> wrote: > > > I'd like to change the default mode of assertion failures to throw. > > > The current default is to warn. In my opinion this is a bad strategy: > > > the engine asserted that something that is expected to be true is not, > > > so executing further is a bad idea. This leaves throwing or bailing > > > out. I think throwing an exception is better than bailing out, so > > > that's what I propose. > > > > Couldn't agree more, but I always assumed this BC break could be > > too big before. Did you make any research on the impact already? > > > > Otherwise +1 > > Nikita put together a search of top packagist repositories to look for assert: > https://gist.github.com/nikic/8311ee63c72573d514217456bf2df552 > > We can't generally know what their ini settings are, though. > > In my opinion this change is worth any backwards compatibility break > as we are choosing the worst setting except for ignoring them > altogether, and can be changed back to the previous value using an > existing ini setting; we just need to put a note in the migrating > guide.
Big +1 on changing the default to throw. The current default of only producing a warning is surprising and can result in code continuing to execute in a state the developer intended to prevent. Theodore
  111006
July 14, 2020 20:43 marcio.web2@gmail.com (Marcio Almada)
Hi!

On Mon, Jul 13, 2020 at 11:52 AM Marcio Almada web2@gmail.com>
> wrote: > > > I'd like to change the default mode of assertion failures to throw. > > > The current default is to warn. In my opinion this is a bad strategy: > > > the engine asserted that something that is expected to be true is not, > > > so executing further is a bad idea. This leaves throwing or bailing > > > out. I think throwing an exception is better than bailing out, so > > > that's what I propose. > > > > Couldn't agree more, but I always assumed this BC break could be > > too big before. Did you make any research on the impact already? > > > > Otherwise +1 > > Nikita put together a search of top packagist repositories to look for > assert: > https://gist.github.com/nikic/8311ee63c72573d514217456bf2df552 > > We can't generally know what their ini settings are, though. > > In my opinion this change is worth any backwards compatibility break > as we are choosing the worst setting except for ignoring them > altogether, and can be changed back to the previous value using an > existing ini setting; we just need to put a note in the migrating > guide. >
I took a look at the top ones + random picks, most are converting warnings to exceptions at least during tests. Still a +1 from me.