Overall Typehint Usage
PHP typehints were introduced in PHP 5. Ever since, they have grown in features and usage. Where are we at the moment ? We scanned the Open Source community repositories. 89% of all PHP code source use types hinting, at least a little.
This number is very high, yet it represents very different situations. Here is a breakdown of the actual coverage of parameters and return type. The graph below presents the % of parameters and return type that are explicitly defined in a code source.
This graph goes from 0% to 100%. This reflects a wide range of situations. The average project has 11 000 parameters and return type to assign, and this may be much higher for the largest projects : up to 170 000 typehints. Yet, the size is no indicator of typehint coverage.
The average is currently 19%, while the median is 11%. This means that type hinting efforts are still in the beginning.
Several bumps are currently hampering the adoption of typehint : + multiple type as argument + error management (by returning multiple types) + class extensions and common interfaces, where adding a type hint means adding it simultaneously to several methods + multiple arguments + arrays, where their content should be typed
There are solutions, already available or coming, to help with all those situations, so those numbers should change in the coming years.
67% of all the typehint are scalar typehints. This shows that typehints are currently used to enforce the existing situation. The methods have been receiving integers as argument, and it was easy to set them as typehint. This is probably the middle step : no typehint, then scalar typehint, then class/interface typehint.
All figures above were produced by running an exakat audit on 815 open source applications.