Assertions
Why are there so many assertions in Zurmo and why are the assertions sometimes in quotes and sometimes not?
The main purpose of adding assertions:
1. Forces stronger type casting.
2. Tightens methods by ensuring the parameters are correctly passed
3. Adds a form of documentation that is easy for someone looking at them to understand more about the method.
Additional information about assertions:
1. The assertions are in strings because… (From the php reference: ”The advantages of a string assertion are less overhead when assertion checking is off and messages containing the assertion expression when an assertion fails.”)
2. Asserts are NOT for error handling.
3. On top of the usual uses, we use assertions to test whether parameter argument types are correct where php cannot do it for us. When php type hinting is possible, it this method is preferred over assertions.
This will run only with debug set to true:
assert('$account instanceof Account')
This will run always:
assert($account instanceof Account)
Two reference links where you can get more information on assertions:
http://www.stanford.edu/~pgbovine/programming-with-asserts.htm