Open
Description
The description in https://github.com/DaveLiddament/php-generics-standard#constructor is a bit unclear to me. If you are passing a literal integer value, it's obvious that T = int
, but what if the value is dynamic?
function test(?int $foo) {
$valueHolder = new ValueHolder($foo);
}
In this case, $foo
can be int
or null
at runtime. However, I would assume that the actual inferred type is T = ?int
. Is that correct?
If it is, then what about this variant?
function test(?int $foo) {
if (null !== $foo) {
$valueHolder = new ValueHolder($foo);
}
}
Here, $foo
is known to be int
, but only through flow-sensitive type analysis. Would T = int
here?
Metadata
Metadata
Assignees
Labels
No labels