PHP Beginner— The Type System Part 1

#[Pragmatic(Kiwi)]
3 min readMay 23, 2022

The most significant features of PHP 7 besides performance boosts is the improved type system.

It took until PHP 8.0 before most key features were implemented. Overall, PHP’s type system has improved significantly over the past few years. The system is maturing and some community projects started to use types to their full extent.

Let’s take a look back in the pats and see the differences between PHP5 and PHP8 Type System.

Firstly, more built-in types were added, they are called “scalar” types. These types are integers, string, boolean and floats. Return types were added so that before PHP 7 you were able to use the type hint only for input parameters, this leading to a mix of doc block types and inline types.

It was a mess

It is convoluted, ugly and hard to read at times.

Some developers who didn’t want to deal with this choose not to use types at all. After all the level of safety was limited since doc blocks aren’t interpreted AT ALL Only your IDE would be able to understand the doc block version.

--

--