PHP in Action Rotating Header Image

Posts from ‘February, 2009’

One behavior != one assertion

Image by libbyrosof via Flickr

The debate on the “one assertion” principle continues. Pádraic Brady and I agree on the general principle, but since he is so categorical in his second article, I needed to inspect his reasoning more closely. It’s clear that our disagreement is more than superficial. The more I think about it, the [...]

One assertion per test—always?

Image via Wikipedia

Pádraic Brady pleads for the principle that a unit test method should have only one assertion. His point is perfectly valid; there are several good reasons why one assertion per method is a smart guideline when writing unit tests. But since he drags up the term “lazy”, I feel the need for soul-searching [...]

Type hints are not hints

Image by Franco Folini via Flickr

As Kevlin Henney pointed out at the PHP UK Conference 2007, PHP type hints are not hints.
Rather, they are instructions to PHP to check the type. That may not be terribly important,
but it’s worth pointing out, since confusing terminology is less confusing if you understand how it’s confusing.
Anyway, I hereby [...]

Smart return values

Image by cackhanded via Flickr

Davey Shafik discusses return values from functions. In the specific case of a function that returns values from a database, he wants to return false on error and an empty array if the data set is empty. He also has a reason for that:
“However, it’s very rare that I care about [...]