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


IMO there’s not a correct answer to this, simply trade-offs.

Given the nature of the library, I’d expect it caters to more experienced users. They’d tend to do more thorough testing during development, so assertions that are skipped in prod may be plenty.

Outside of tests, I usually limit `assert` to checks that can’t be (easily) expressed through the type system – nonempty arrays, things that would be generics, etc. They work well alongside static analysis tools like PHPStan.

Really depends how thorough and accurate your tests and types are. In a legacy system that’s been cobbled together, you’d probably want checks that can’t be disabled at runtime.