Reply To: Should we use “assert()”?


In PHP 5 it was almost entirely useless. In PHP 7 it became useful but you had to adjust INI settings, which means libraries couldn’t rely on it but applications could. In both PHP 5 and 7 the default was to emit a warning and then continue. That’s not a great experience.

So I changed the default assertion failure mode to throw for PHP 8. I now encourage libraries or apps explicitly supporting PHP 8 to use asserts, with a caveat: I don’t recommend changing the exception type. And of course, normal assertion recommendations apply: don’t include anything with side effects in the assertion and so on.