【发布时间】:2020-10-07 15:16:20
【问题描述】:
是否可以在 Psalm 中使用 @param-out 来操作 this 或 self 中的幻像类型?示例:
/**
* @template T
*/
class Foo
{
/**
* @param T $t
*/
public function __construct($t)
{
$this->t = $t;
}
/**
* WRONG:
* @param-out Test<S> $this
*/
public function test()
{
// Also this doesn't work:
$this->t = new S();
}
}
一个用例可能是例如幻像类型设置为Open 或Closed 的文件类,调用$file->open(); 将T 更改为Open。
【问题讨论】: