Reduce boilerplate code with PHP 8
summary
Demonstrates concrete PHP 8/8.1 changes that cut boilerplate: removing redundant docblocks, using constructor property promotion to drop repeated names from four occurrences to one, switching getters/setters to readonly properties (writes after construction trigger a fatal error), replacing switch blocks with the match expression that returns values, using the nullsafe operator to safely return null for missing nested objects, and using named arguments; recommends phpcs-fixer and Rector for automated transforms.
AI-written summary · about
chapters (15)
- 0:00Start
- 2:18Doc Blocks
- 8:07Attributes
- 9:12Why Do We Use Getters
- 9:42Read-Only Properties
- 13:02Immutable Objects
- 13:26Read Only Properties
- 17:50Match Expression
- 18:55Null Safe Operator
- 20:02Named Arguments
- 21:17Recap
- 22:06Constructor Variables
- 24:00Live Coding
- 25:53Type Hinting
- 29:34Remove All the Getters and Setters








