The Coding Studio Inc. Tips
php[architect]: The Case for Generics in PHP
The php[architect] site has posted an article pulled from their November 2018 issue providing a case for generics in PHP. To elucidate their merit, we will look at how they might fit within the evolution of PHP's type system to put us in a position to write more robust software: "How can I signal that my method will return a Collection of User objects? And why would I want to do that?" The article starts with a look at generics in other languages and how they're handled (such as Java and C#). From there they shift over to PHP, giving a code sample of a class that is typed to only accept one kind of value for its constructor. They provide an update for this that would work in PHP 7.4 (with typed properties) and how with the help of generics it would be simpler to define a more dynamic type requirement, allowing for more generalized class descriptions.