Session

A Case for Generics in PHP

PHP 7 has brought us improved support for Types, making us less reliant-upon annotations. Yet we still can't signal that a method should return an array of User objects: function foo() : User[]

What makes an Array of Users so special? What if we'd like to return a HashMap of a given key & value?

We'll explore use-cases for defining composite objects and leveraging Generics to avoid repeating ourselves.

In 2016, Ben Scholzen and Rasmus Schultz drafted an RFC for "Generics in PHP" https://wiki.php.net/rfc/generics

Having worked with these constructs in Java and C# in past lives, I can offer several examples of practical use-cases for them, and help bolster a case for their adoption in PHP.

In the end, we should arrive at how they would nicely complement the most recent enhancements to PHP7's Type System.

Chris Holland

Director, Engineering, TriNet

Actions

Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.

Jump to top