# Changing default assertion mode to throw exceptions

- Thread: https://externals.io/message/110978
- Original archive: https://news-web.php.net/php.internals/110978
- Started by Levi Morrison on 2020-07-13T17:36:18+00:00
- Messages: 10
- 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

---

## #110978 — Levi Morrison — 2020-07-13T17:36:18+00:00

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

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.

---

## #110979 — Marcio Almada — 2020-07-13T17:51:58+00:00

URL: https://externals.io/message/110978#110979 · In reply to: #110978

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.
>
> --
> 
> 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 — Levi Morrison via internals — 2020-07-14T15:10:18+00:00

URL: https://externals.io/message/110978#111000 · In reply to: #110979

> > […]
>
> 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 — Theodore Brown — 2020-07-14T16:19:26+00:00

URL: https://externals.io/message/110978#111003 · In reply to: #111000

> 
> > […]
> 
> 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 — Marcio Almada — 2020-07-14T20:43:15+00:00

URL: https://externals.io/message/110978#111006 · In reply to: #111000

Hi!

On Mon, Jul 13, 2020 at 11:52 AM Marcio Almada <marcio.web2@gmail.com>
> wrote:
> > […]
>
> 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.

---

## #111075 — Levi Morrison via internals — 2020-07-20T13:48:48+00:00

URL: https://externals.io/message/110978#111075 · In reply to: #110978

>
> 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.

Hello, everyone. It's been a week and I have only heard a bit of
positive feedback and no pushback. Anyone else want to reply?

---

## #111100 — Brent Roose — 2020-07-22T08:48:06+00:00

URL: https://externals.io/message/110978#111100 · In reply to: #111075

Hi Levi

I personally almost never use assert, and actually assumed it would throw an error, so this sounds like a good change! 

Have you done research on how this would affect the top-1000-ish popular packages like Nikita does?

Kind regards
Brent

> 
> 
> 
> > […]
> 
> Hello, everyone. It's been a week and I have only heard a bit of
> positive feedback and no pushback. Anyone else want to reply?
> 
> -- 
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111125 — Gabriel Caruso — 2020-07-22T15:05:16+00:00

URL: https://externals.io/message/110978#111125 · In reply to: #110978

> 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.
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php


Hello Levi

+1 on this one, I use assertions on my local development, and we also have
that
on `doctrine/coding-standard` (
https://github.com/doctrine/coding-standard/pull/47).

I think throwing an exception is indeed a better way to make the most out
of it.

---

## #111126 — Nikita Popov — 2020-07-22T15:07:55+00:00

URL: https://externals.io/message/110978#111126 · In reply to: #111125

On Wed, Jul 22, 2020 at 5:05 PM Gabriel Caruso <carusogabriel34@gmail.com>
wrote:

> 
>
> > […]
>
>
> Hello Levi
>
> +1 on this one, I use assertions on my local development, and we also have
> that
> on `doctrine/coding-standard` (
> https://github.com/doctrine/coding-standard/pull/47).
>
> I think throwing an exception is indeed a better way to make the most out
> of it.
>

I'm also +1 on this change. Throwing an AssertionError is clearly the
better default experience, and changing back to the previous behavior is
super simple.

Nikita

---

## #111127 — Kalle Sommer Nielsen — 2020-07-22T15:53:26+00:00

URL: https://externals.io/message/110978#111127 · In reply to: #110978

Hi

Den man. 13. jul. 2020 kl. 20.37 skrev Levi Morrison <levim@php.net>:
>
> 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.

+1 on this. I was recently surprised why this wasn't the default either


-- 
regards,

Kalle Sommer Nielsen
kalle@php.net
