Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

The inconsistencies of PHP

The inconsistencies of PHP

Perhaps I am somewhat of a 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 the 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.

May 2015
In May 2015, I began to write the initial code for the Zenith Parsing Engine and the ZenLang language. This article inspired my initial formal specification.

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. A range of PHP-based functionalities powers my website. 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 horrible 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 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!

urlencode() and utf8-encode - again 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 adore it, partly because it's such a powerful web development language with a fantastic collection of documentation on it but also because it's easy enough to get your head around the problems and inconsistencies of it.

Let's also not forget PHP's errors still report issues with paamayim nekudotayims (::) in them!

But what do you think? Comment below.

Posted by jamiebalfour04 in The Web
php
inconsistent
failures
flaws
htmlentities
spaces
underscores
dashes
random
Comments
Powered by DASH 2.0
Scan and keep for the latest article or review every time!
https://www.jamiebalfour.scot/redirect/action/latest-article/