Morning All,
I'd like to draw some attention to how poor assertions are in PHP.
The current assertion API is not usable in my opinion; it has a considerable overhead, relies on eval(), and is generally poorly implemented.
I have done some work toward implementing assert at the Zend level, giving assertions a more modern, usable feel to them.
https://github.com/krakjoe/php-src/compare/assert
This implementation of assert removes the old implementation and associated functions and INI settings, and replaces it with a single INI setting to control assertion compilation.
Failed assertions throw an AssertionException (which extends ErrorException with a severity of E_ERROR), setting the message of the exception to the expression asserted.
The syntax of assertion is the same as [all] other languages:
T_ASSERT expr ';'
This means that assert("some code here") will pass assertion causing no error, because strings are no longer treated as code, because eval is evil();
Setting zend.assertions=0 system configuration setting will stop ZEND_ASSRT compilation.
So, we have:
try {
assert (PHP != JUNK);
} catch(AssertionException $ex) {
printf("Assertion failed: %s\n", $ex->getMessage());
printf("Something is horribly wrong ...\n");
}
Better, no ??
Cheers
Joe