I'm tired of reading the same message all time: "PHP sucks."

But most of these critics haven't looked at PHP since 2012, and a lot has changed since then.

Let's take a look at the language changes that have happened since PHP 5.4 was released.

Traits (PHP 5.4)

PHP 5.4 introduced traits, which allow for composition over inheritance. You can have traits and include them in every class.

Short Array Syntax

Gone are the days of writing array() like a caveman. You can now use square brackets for short array syntax.

Array Destructuring

Assigning an array to a temporary variable is a thing of the past. You can now use array destructuring to directly assign variables from an array.

First-Class Variadic Functions

You can pass as many arguments to a function as you want using the ... syntax.

Generators

Need to do something memory-intensive in a memory-efficient way? Generators are the way to go.

Anonymous Classes

Need a new class but can't be bothered to make a new file? Anonymous classes are the solution. They can implement an interface just like any other class.

Trailing Commas (PHP 7)

No more worrying about adding a trailing comma to a function call or method call.

Arrow Functions

PHP has arrow functions too! They're not exactly like JavaScript's, but they're a great addition to the language.

Null Coalescing Operator (PHP 7)

No more checking for null before assigning a value. The null coalescing operator has got you covered.

Null Coalescing Assignment Operator (PHP 7.4)

And if you need to shorthand that null coalescing operator, there's an assignment operator for that too.

Null Chaining Operator (PHP 8)

No more checking for null before calling a method. The null chaining operator is here to save the day.

Named Arguments (PHP 8)

Sick of using null to skip over optional arguments? Named arguments are the solution.

Attributes (Annotations)

PHP has attributes now, which can be used to add annotations to classes, methods, arguments, or properties.

Improved Error Handling

No more needing a variable for an exception just to return false. PHP has improved error handling now.

Match Statement (PHP 8)

No more switch statements that are a mile long. The match statement is a more compact and readable way to write switch statements.

Weak Maps (PHP 7.4)

Weak maps are here, and they're way better for memory than arrays. Plus, you can use objects as keys.

Enums (PHP 8.1)

Enums are finally here! You can create enum classes with values and methods, and even use them as type hints.

Type Safety

PHP now has typed arguments, return types, union types, intersection types, and more. You can even use type hints for enums!

Constructor Property Promotion (PHP 8.0)

Gone are the days of verbose constructors. Constructor property promotion is here to reduce boilerplate code.

ReadOnly Properties (PHP 8.1)

Need to mark a property as read-only? There's a keyword for that.

Performance

PHP has experienced a 400% performance increase between 5.6 and 7, and another 20% between 7 and 8. It's fast enough for most use cases, and if you need a specialized use case, use a specialized language.

In conclusion, PHP is not dead, nor is it sucking anymore. The language has undergone significant changes since 2012, and it's high time to revise our opinions about it.

With the introduction of traits, short array syntax, array destructuring, and a host of other features, PHP has become a more efficient, readable, and maintainable language.

Add to that the improvements in error handling, the introduction of attributes, and the long-awaited arrival of enums, and it's clear that PHP has evolved into a robust and reliable choice for web development.

So, the next time someone tells you that PHP sucks, you can confidently tell them that they're just stuck in the past.

← Go back to the blog