05 Php8 Home

05 Php8 Home

Feature 1

One I ran into at work is that value-returning methods are now required to specify their return type. The error does tell you what return type should be used, so it isn't difficult to implement, but it can be annoying to have the site break just because of that. You can also add an attribute to suppress the error, but like I said, it's easy to fix. I know this isn't necessarily a feature, but I wanted to mention it since I have personal experience.

Feature 2

Speaking of attributes, that was one of the new features. Implementing the uses of attributes has technically always been possible, but more manual work was needed. They are just metadata, so they don't change the code itself in any way. Instead, from my understanding, they are used to optimize code runtime. You can also make custom attributes. For example, they could make encapsulation easier by making your class and attribute and assigning it to another class.

Feature 3

Something else I ran into at work as a result of my first paragraph was the mixed type. There was some vendor code that wanted return types, and it suggested mixed for a couple. As far as I can tell, it's the equivalent of var in C#, still being able to provide some sort of type without knowing the specific type. It also includes null, so you can't make it nullable.

Summary

It appears that a lot of important features were added in PHP 8. Some may argue that some should've been included way earlier. Also, I feel like PHP needs to change something about their deprecated features because unlike in other languages where something may be deprecated but still usable, PHP just breaks your site.