kphp
kphp copied to clipboard
Primitive type as `class-string`
/**
* @kphp-generic T
* @param class-string<T> $t
*/
function foo($t) {
}
foo('int');
Compilation of this code fails with
Starting php to cpp transpiling...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Deduce implicit types and casts, gen by generics-reification.cpp:192
a38a375e.php:9 in global scope
Class int not found
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Deduce implicit types and casts, gen by generics-reification.cpp:319
a38a375e.php:9 in global scope
Couldn't reify generic <T> for call.
Please, provide all generic types using syntax foo/*<T>*/(...)
Maybe it's worth to rename (or alias) the annotation into type-string
to avoid confusing with by class
?
And don't forget about classof
.