Re:A look at modern PHP
by nucleardog on Tuesday May 05, 2020 @12:56PM
(#23082105)
We do similar (strict_types, declare parameter and return types, etc), but don't go as far as the Java-style collection classes except where absolutely necessary.
As a mostly-acceptable alternative, we just type hint as array and document the actual containing types in the phpdoc block and run phan for static analysis to catch any potential screwups.
/**
* Method for converting Foos into Bars
*
* @param Foo[] $foos
* @return Bar[]
*/
function convertFoosToBars(array $foos): array
{
// ...
}
In theory this isn't perfect. In practice we haven't run into any issues yet.
As a mostly-acceptable alternative, we just type hint as array and document the actual containing types in the phpdoc block and run phan for static analysis to catch any potential screwups.
In theory this isn't perfect. In practice we haven't run into any issues yet.