Chapter 4: Scalar, Arrays, and Special Types
Welcome to Section 2. In this part of the book, we are going to look at something that has become much more of a first-class feature in modern PHP: types.
The release of PHP 7 marked a significant turning point in the history of PHP. It ended a long period of stagnation that included the abandonment of a whole version – PHP 6. With PHP 7, we got some significant and highly useful changes to the language, and one of those was the introduction of scalar type declarations:
https://www.php.net/manual/en/migration70.new-features.php
PHP 7 brought the advent of scalar type hints and strict type checking. This allowed us to write code with a clearer API and built-in assurances that parameters are at least of the correct type, which allowed a significant reduction in boilerplate code to confirm parameters are correct. It also brought in the concept of return types. These two added features tipped the...