Notification Free PHP Coding
This is a reply to http://100days.de/serendipity/archives/50-Notification-Free-PHP-Coding.html. Gaylord Aulke’s opinions are normally quite valuable. There are a couple of arguments (just read the comments) in both directions and to be fair, Gaylord also said, that his opinion is different for frameworks and libraries.
Even though I tend look into PHP notifications (some code produces so much of them, that you can only ignore them), I wasn’t really sure what my final position on Notification Free PHP Coding is and I was not too strict about it.
That changed today.
While demonstrating my reporting frontent for PHPUnit to the customer this month, I had to find out that it’s JUnit/XML logger sometimes produces broken XML files: You can get a “PCDATA invalid Char” exception when loading it with DOMDocument::load(). Sebastian Bergmann encouraged me to send a pull request on github, which is nice. Except that I never contributed to PHPUnit before. Nor did I actively use github. Like Lars Jankowfsky I tend to stay with SVN, when possible (that’s probably worth another blog post).
It was easy to fix the bug (actually, it turned out to be more complex) and after reading a couple of git manuals, I found out how to commit, push and send a pull request. The only thing I didn’t notice is that I used the constant _ENTQUOT (undefined) instead of _ENTQUOTES (defined) as an argument to htmlspecialchars() for some reason – this is why I recommend to focus on each line of code to other people…
htmlspecialchars(self::convertToUtf8($string), ENT_QUOT, 'UTF-8')
Not a big thing, if I would have seen the PHP notice!
Notice: Use of undefined constant ENT_QUOT - assumed 'ENT_QUOT'
It was not possible to see it, not because I did not look at the error messages or the test results, but because the default config for PHP on Ubuntu is _error_reporting = E_ALL & ~ENOTICE. To use an undefined constant is just plain wrong and leads to an undefined state of the software – it must be noticed. Also, whenever there are too much notices, you won’t be able to spot it. Therefore the only way to avoid it is to produce notification free code. I don’t want something embarrassing like this ever happen to me again.