0

My team and I were having a discussion about unit tests, tests in general and runtime tests using assert();.

In my opinion, assert()s are powerful indicators when used with a good error/exception handler and project-wide error levels - in combination with realtime analysis using Kibana for example.

My colleagues argued that there is no use-case for assert(), at least in PHP 5 (because further functionality was added in PHP 7 only).

My question is, when is it technically useful to implement assert()? I am explicitly asking for a technical advantage, not a personal opinion.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151

1 Answers1

0

It makes error handling much easier on the coder by being able to build your error handling function then set the handler by ASSERT_OPTIONS then on operations that have the chance of failing using ASSERT() This can of course also be done by TRY CATCH but it is much longer and more drawn out. I typically use it while calling some functions that rely on prerequisites(such as a sucessfull file upload, an sql transaction, calling session variables etc... that for any reason could fail and you want to capture the error and other pertinant information and handle it in one way across the board like sending an email to the webmaster, storing it in an sql table, etc.....

PC3TJ
  • 852
  • 5
  • 16