Psalm
Get started
Documentation
Paid support
Plugins
Blog
GitHub
<?php /** * @template M of self::FETCH_* */ class Statement { public const FETCH_INT = 1; public const FETCH_STRING = 2; public const FETCH_FLOAT = 3; /** * @template T of self::FETCH_* * @param T $_mode * @psalm-this-out self<T> */ public function setFetchMode(int $_mode): void {} /** @return (M is self::FETCH_INT ? int : (M is self::FETCH_STRING ? string : float)) */ public function fetch(): mixed { return 1; } } $s = new Statement; /** @psalm-trace $s */; $s->setFetchMode(Statement::FETCH_INT); $_r = $s->fetch(); /** @psalm-trace $_r */; $s->setFetchMode(Statement::FETCH_STRING); $_r = $s->fetch(); /** @psalm-trace $_r */; $s->setFetchMode(rand(0,1) ? Statement::FETCH_FLOAT : Statement::FETCH_INT); $_r = $s->fetch(); /** @psalm-trace $_r */;
Snippet created on July 27 2023 at 21:19 UTC
Settings
Get link