Skip to main content

Posts

Showing posts from October, 2012

PHP Assertions

I stumbled upon assertions in PHP today, though why I didn’t know they exist after working in the language for so long and what I was originally looking for when I came across them are both mysteries. And with the increasing focus on software quality in the PHP community, I wondered why I hadn’t seen them used by others. I decided to ask around. I asked a few friends if they knew about assertions. They did. I asked if they used them. They didn’t. Remi Woler : I think nobody has found a good use case. It weaves tests into code. How are you going to recover from a failed assertion? Davey Shafik : They kinda suck. For example: assert('mysql_query("")') It's a string of code that gets eval’d. So, PHP assert didn’t get stellar endorsements from people whose opinions I respect. My main experience with assertions comes from C where they are defined as macros. Its argument must evaluate true, otherwise the program terminates with an error. These checks can be st