Big PHP Niggle

I need a quick bitch.

I love PHP. It’s everywhere. All my sites are written in it. My CMS is written in it. My blog engines, WordPress and b2evolution, are written in it. It’s free. It runs on any platform. Hosts all support it. With PHP 5 they’ve even done a lot of work on PHP4’s main downfall – lack of OOP support.

One thing really pisses me off though – it’s totally inconsistent.  Consider these two functions:

  1. strstr — Find first occurrence of a string
  2. in_array — Checks if a value exists in an array

Take a close look. See the signatures?

string strstr ( string $haystack , mixed $needle [, bool $before_needle ] )
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )

In in_array the first parameter is what you’re looking for and the second is what you’re looking in (more or less consistent with preg_match).  In strstr (and its derivatives) this order is reversed. Who on Earth let that slip through? I’m yet to find a free text editor that will tell you which parameters a given function expects (Dreamweaver does a decent job but it’s bloody expensive for a text editor!) the way Visual Studio does for C#, which I use a lot in work.  Given that situation, you’d expect consistency in this sort of thing.  Apparently not so. Instead, every time I want to use one of these functions I have to do a quick Google to bring me to the PHP manual page to tell me which order the parameters come in.

Of course they can’t even fix that without breaking backwards compatibility either, so we’re probably stuck with it.  Bloody marvellous!

Author: nerd.

An experienced IT professional, I used to run a number of small websites and spend a lot of time tinkering with my sites or my PC - back when I had free time.

3 thoughts on “Big PHP Niggle”

  1. You highlighted another inconsistency – some functions are underscored, some are not. That bugs the crap out of me. I don’t google though, it’s easier to just type php.net/thefunction — even if I misspell the function it brings up a list of suggestions.

  2. You’re totally right Jem, I’d forgotten about that one. The truth is I did kind of pinch this from a site I read ages ago: it was a big rant about how bad PHP is. For the most part I thought it was nitpicking or didn’t relate to what I was doing anyway, but I really did agree with the inconsistency in parameters and, indeed, underscores in function names.

    I think it’s a toss up for me between your way and googling php functionname. The benefit of google is even if I’ve no idea what the function’s called I can usually find it by telling google what it does.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.