If you're anything like me, you enjoy writing code a lot more than you enjoy testing and debugging it. If we could produce higher quality code with less test and debug effort, we'd jump at the chance, right? Well, in this new article from SitePoint, you just might have a way to get this done.
In Effortless (or Better!) Bug Detection with PHP Assertions, the author explains how using "assertions" (or "run-time checks that a PHP expression is true") can help you and your code get along just a little bit better. They can help you do some sanity checks on the information that you receive from other scripts, or even variables inside of your own scripts - just to double-check. The assert() function has been standard since PHP4, and, according to the PHP manual, should be used as a debugging feature only.
There's even mention of an external package, phpAssertUnit, that will stay "out of the way" by providing a separate Assertion Reporter window to report on failed assertions. It also provides assertions capabilities for JavaScript as well as PHP.
For more information see these manual pages:
Assert()
Assert_options()




