Learn about strict data types and scalar type hints in PHP 7. Find out how to use this new and controversial feature consistently in your own code.
- [Voiceover] Hi, I'm David Powers. PHP is a dynamic, loosely typed language, but the requirements of complex applications have brought increasing demands for strict type checking. In this course, Strict Data Types in PHP, I'll explain how these demands have been addressed without abandoning the language's weakly typed roots. After reviewing typed juggling and typed casting, we'll look at the different levels of Strict Data Types in PHP 5 and PHP 7.
Then, through a series of practical examples, I'll demonstrate how to use parameter and return type declarations. This detailed coverage of the most controversial aspect using scalar type declarations in weak and strict modes in PHP 7. This is a short course, but it's packed with information that everyone migrating to PHP 7 should be aware of. So let's get on with Strict Data Types in PHP.
First, he introduces the basics of type juggling and type casting in PHP. Then, he reviews strict typing with objects, arrays, and callback functions, which were introduced in PHP 5. He also reviews scalar type hints in PHP 7, which can have unexpected side effects for unwary developers. David concludes with a frank assessment of the practicalities of strict typing, and a simple recommendation that will help most developers use the new feature: define in strict and execute in weak.
- Implicit and explicit type casting
- Using strict data types
- Declaring return types in PHP 7
- Creating scalar parameter declarations and scalar return type declarations
- Assessing the merits of strict data types