Back to Top

Monday, April 06, 2009

Learning is never done

2500281256_537ee792bd_b I’ve been using PHP for a while now and thought that I knew the available functions (at least the generic ones) pretty well, but recently I got surprised: a recent entry on the Me and My Database blog pointed me towards http_build_query and in the same category I found parse_url. This is significant to me, since I used some hacked-up regular expression to do the same in the webhoneypot. So I ripped out my regex and replaced it with parse_url. There are at least three advantages to using built-in functions:

  • they are fast
  • they are probably better tested than your code
  • your code will be shorter (and less to maintain for you)

So next time you want to do something, take a look around, maybe there is a PHP function which already does what you want (or almost what you want). Admittedly, the organization (naming) of the functions is not always the most consistent, intuitive one, but the searching effort is well worth it.

Picture taken from triplezero's photostream with permission.

1 comment:

  1. I guess you should learn new stuff every day. If you don't it means that your life is slowly losing it meaning. And who'd want that?