PHP in Action Rotating Header Image

Posts under ‘PHP’

Real programming with PHP 5.3 (part 1): array processing

You may have heard of the new features that are scheduled for PHP 5.3, but who knows what they can be used for in real programming? I took the time for some experimental research, and came up with a few examples.
At the PHP UK conference, I saw Sebastian Bergmann’s presentation on lambda functions, closures and [...]

Is agile development a religion?

Automobile skeptic: Driving doesn’t always work. I tried it once and crashed into a tree.
Automobile zealot: How did that happen?
Skeptic: I was driving down Hazel Street, reading a magazine. And then suddenly, out of the blue, I hit the tree.
Zealot:  But you can’t read magazines while driving a car!
Skeptic: Why not?
Zealot: Because then you’re not [...]

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 [...]

How code comments deteriorate

There was a lot of disagreement on the value of code comments after my earlier post Comments considered harmful. Perhaps the most important objection that was raised was the idea that it’s OK to improve the code, but it’s even better to keep the comments in addition to the improved code.
As one [...]

How harmful is “harmful”?

Conflict is not a bad thing. That is, if it leads eventually towards clarity and understanding rather than confusion and misunderstanding. And it’s almost always better to have a conflict openly than to sweep it under the [...]

Comments considered harmful

There is too much old advice in PHP. A recent case comes from the PHP Advent calendar. Eli White is a strong believer in commenting code, including inline comments inside functions.
Unfortunately, he’s at least 10 years too late. This used to [...]

The one-line web framework

The core of your average web framework is a Front Controller. Front Controllers are commonly considered complex and esoteric. That’s a myth. I sometimes brag that I can construct a Front Controller in 15 minutes. Actually, it’s doesn’t take quite that long. In PHP, a Front Controller can be simplified to just one [...]