PHP Insanity III
Mark Mzyk | January 5, 2008
The holidays are over, so that means it’s time for PHP to bring me back to reality by crushing my brain between my skull.
Today’s segment is presented by the PHP function header().
If you’ve had any experience coding with PHP, you’ve probably seen the header function used in many difference places. I certainly have. In fact, the header function actually works fairly well. It doesn’t have crazy returns like certain other functions, probably because it doesn’t return anything at all.
Yet in typical PHP fashion, it is still manages to screw things up. How? It’s overloaded.
I’m going to stop here and admit that I’m no HTTP expert, but this post reflects my understanding. Of course correct me if I’m wrong, but I think PHP could have handled this situation better.
How is the header function overloaded? You see, there is both a header and a status code in HTTP. These are, in fact, not the same thing, although they are related to each other – but still, not the same thing.
Yet in PHP, the header function can be used to set both of these. Would it have been so difficult to define an HTTP status method, thereby clearly separating the functionality? That would have made my life easier. Then I’d be able to glance at the function name and know definitively what action it was performing without having to decipher the information passed into it. Less confusion would result, leading to less stress in my life.
PHP’s implementation of this function violates the single responsibility principle, if you buy into the principles of object-oriented design. And I think PHP should buy into those principles, since PHP continues to add OO features.
It’s because I continue to find issues like these that I agree with the Tim Bray’s prediction for PHP.
Who knows what the next installment of this series will bring, but I have no doubt I’ll continue to discover more PHP insanity.
Reference Links:
Previous Entries in this series: