Skip to editor
Psalm
Docs
Playground
Plugins
Blog
Paid support
Share
Fix issues
Show original
PHP
Settings
<?php /** * @template TValue * @template TError of Throwable = RuntimeException */ final class Result { /** * @param TValue|null $value * @param TError|null $error */ public function __construct( public readonly mixed $value = null, public readonly ?Throwable $error = null, ) {} } // Result<int> means Result<int, RuntimeException>: code written before // TError was added keeps working, with no MissingTemplateParam /** @param Result<int> $result */ function handle(Result $result): void { $error = $result->error; /** @psalm-trace $error */; // RuntimeException|null } /** @param Result<int, LogicException> $result */ function handleLogic(Result $result): void { $error = $result->error; /** @psalm-trace $error */; // LogicException|null } // Method templates can default to another template /** @template T */ interface Option { /** * @template TResult = T * @param (callable(T): TResult)|null $map * @return Option<TResult> */ public function map(?callable $map = null): Option; } /** @param Option<int> $option */ function check(Option $option): void { $same = $option->map(); /** @psalm-trace $same */; // Option<int> $flags = $option->map(fn(int $i): bool => $i > 0); /** @psalm-trace $flags */; // Option<bool> }
Issues
Types
idle
Saved Nov 2 2026 18:37 UTC
⌘/Ctrl+Enter
run
⌘/Ctrl+S
share
F8
/
⇧F8
next/prev issue