/**
* @param int $a
* @return float[]
*/
function foo ($a) {
echo "You passed in the integer $a";
return [$a * 1.0, $a * 2.718];
}
Augmented Types simply provides a way of enforcing argument and return types on function calls in PHP. It parses a given function’s type information from phpDoc-style type annotations (based on the phpDocumenter project), and it stores this information efficiently for later enforcement during runtime.
As PHP typehints (in functions) are limited to objects and arrays, this might improve coding indeed (especially in big teams).
Alternative could be to introduce a few classes for the basic types. Think Objective-C, where NSInteger
contains an int
for example. That way you could force it without the need for a runtime extension. The custom types will of course create overhead, yet that’s something that needs to be benched before dismissing the idea entirely.