Search code examples
phppsalm-php

Does Psalm supprt @param-out for "this"?


Is it possible to manipulate phantom types in Psalm using @param-out for this or self? Example:

/**
 * @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();
  }
}

A use-case for this could be e.g. a file class with phantom type set to Open or Closed, and calling $file->open(); changes T to Open.


Solution

  • No. There's a pull request about it that might or might not be merged, using @param-self-out.