All the Reasons why I hate PHP

0. No out-of-the-box framework for MVC or other frameworks for organizing your homepage

If you want to use a MVC framework or a template system, you either have to rely on a 3rd party implementation or write your own. No such thing in the PHP standard library.

1. PHP is a weak-type language

In PHP we do not care about types. If you used this variable for Foo, but you want to store an integer in it? Sure, why not? In PHP, we define the type of our variable/return-value/parameter in a comment. If you accidentally use the wrong value in a 200 lines long algorithm, PHP wouldn't even bother you that you are using the parameter value instead of a value inside a table. 

2. Lack of proper and clear documentation

Although every function in PHP is documented, you have to think twice in some cases. A good example is the str_replace function. The description for str_replace says the function is declares as following:
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
You would think that the $search value is the string you want to perform the string replace function on until you see the subject parameter. But wait, maybe subject is the value you want to search for, or wait - is that $replace?
In C#, it is solved as string Replace(string oldValue, string newValue). 
A better declaration would perhaps be:
mixed str_replace ( mixed $oldValue , mixed $newValue , mixed $subject [, int &$count ] ) 

3. Lack of design for secure code

This is a side-effect of that it is a weak-type language. Instead of defining that this parameter is an integer (well, those of us that actually write comments have this here but comments does - surprisingly not have any affect on our code execution) you have to manually check that it is an integer. PHP almost got this fixed by adding type-hinting where you can define the types of the parameters to your functions. But there is a catch (as with everything else in PHP) - you can only use type-hinting if there are objects. Arrays, integers, strings, etc. are not supported for this feature. This way you have to add if checks for every single variable then perhaps throw an InvaldiArgumentException if you integer is a string instead. 

4. No overloading of functions

For whatever reason, PHP does not support this feature. If you have a "function getUser($userID)", you cannot write "function getUser($userID, $password)". Amazingly enough, PHP does have default parameter values though. 

5. No consistent style of API functions

One example is the DateTime object and other PHP library functions. Most functions in the PHP library are like some_function(). Then suddenly DateTime has a function named someFunction() instead. Although I prefer the last notation, my code gets inconsistent when I use different programming styles to call simple library functions. 

6. Every variable is declared with a $

I have to find the Alt Gr button then hit the 4 key to get a dollar sign. Of course, var is another key extra, but it is a lot easier to type than a $ sign.

7. Where are my enums?

PHP does not support enums. Instead we define our values as consts under a class. Want to make sure your value is a valid "enum"? Then you must write a function for that.

8. Lack of good habits in example code and forum threads

PHP is an incredibly simple language. Someone can easily learn PHP if they have any background in another programming language, and people with no programming background can also easily read and understand PHP code. There is one problem with this: The easier a language is, the lower quality will there be on code floating around the net. This makes it harder to become really good at writing good PHP code as most of the example codes around the web contains at some point bad habits which prevents you from learning how to write good PHP code. 

9. What's up with the underscores?

I have to write __ when I override system functions like toString and constructor. Why can't I just write a function Foo() as the constructor declaration for my class Foo?

 

PHP is not a bad language, neither a good one. It seems that PHP is getting old and more and more hairy after time. If I had the choice, I would write my homepage in C# or Java if this was an option. Although there is a lot of hate around PHP, PHP is still good in some cases.