# The inconsistencies of PHP

Perhaps I am somewhat of language snob, so forgive me if I come across that way in this article but I do believe that PHP is a hugely inconsistent language.

In this article I am going to explain my findings I have found when I have been working with this language. I am only criticising the syntax of PHP, not what it does because it is still by far one of my favourite programming languages.

## Introduction

As I say, I am a bit of a language snob - I like languages that are easy to read, write and remember. A programming language with inconsistencies is not a language I consider to be any of those three properties. As such, I consider PHP to be one of those inconsistent languages.

By saying all of this, I do use PHP on a daily basis. My website is powered by a range of PHP-based functionalities. I also really love PHP for what it can do, and whilst I do very occasionally have to check out the amazing documentation provided in order to get the function name I am looking for, I still love it as a language because of its capabilities.

Now I am not saying that PHP is the only language with horrible syntax, but if you compare it to a language like Java, the syntax is pretty darn consistent throughout.

Java
int i = 10;
ArrayList<Integer> arr = new ArrayList<Integer>()


## A look at some of the problems

PHP has a random collection of inconsistencies that are everywhere. I quote Jeff Atwood (whose article came up first on a search here) here:

PHP isn't so much a language as a random collection of arbitrary stuff, a virtual explosion at the keyword and function factory.

I've been using PHP for over two years as my main programming language and have noticed a few really bad inconsistencies throughout the language including:

nl2br() - new line to break. Why the heck has this got a 2 rather than a to?

file_get_contents() - we have underscores.

fopen() - an old C style construct. So we now have two ways of opening a file, but one way only has an f for file and the other has the full word file.

filemtime() - stands for file modified time. Should that not be file_modified_time or, like the old C-style, fmtime?

htmlentities() - now I'd really like the underscores here!

strpos and str_replace - one has an underscore the other does not!

## Parameter ordering

The order of parameters sometimes also gets messy:

For  str_replace :

PHP
str_replace(search, replace, subject)


Basically for this it follows (ignoring the replace parameter) search -> subject.

Then we come to the  strpos which obtains the first position of a character or string within a string:

PHP
strpos(subject, search)


Now it is subject -> search so the whole concept has flipped.

## Conclusion

I in no way hate PHP. In fact, I do actually adore it, partly because it's such a powerful web development language which has a fantastic collection of documentation on it but also because it's easy enough to your head around the problems and inconsistencies of it.

But what do you think? Comment below:

Posted by jamiebalfour04 in The Web
php
inconsistent
failures
flaws
htmlentities
spaces
underscores
dashes
random