4 ms·
PHP doesn't have loose typing anymore, if you make a function parameter with a specific type: function test(bool $param) {} You will get an runtime error
by Ciantic 3y ago
PHP doesn't have loose typing anymore, if you make a function parameter with a specific type:
function test(bool $param) {}
You will get an runtime error if you call it with wrong type:
Fatal error: Uncaught TypeError: test(): Argument #1 ($param) must be of type boolean
However generics are probably costly to typecheck runtime? I haven't studied the reason why there is not generics planned.
- WesolyKubeczek 3y agoIn a dynamic interpreted language there is no value of having generics over duck typing or omitting types altogether (and you can narrow down by specifying interfaces). Compiled languages generate a version of your function<T> for every T encountered in the codebase.
- usrusr 3y agoFor completeness: other compiled languages elide that T and use the types in angulars only to emit errors during compilation. Also perfectly fine, but certainly not any help in absence of static compilation.