Psalm
Get started
Documentation
Paid support
Plugins
Blog
GitHub
<?php /** * @template T of array<string, mixed> */ final class Props { /** * @param T $props */ public function __construct(private array $props = []) { } /** * @template K of key-of<T> * @template TDefault * @param K $propKey * @param TDefault $default * @return T[K]|TDefault */ public function getProp(string $propKey, mixed $default = null): mixed { return $this->props[$propKey] ?? $default; } } /** @psalm-trace $data */ $data = (new Props(['title' => 'test', 'value' => 30]))->getProp('value', 0); print_r($data);
Snippet created on August 13 2022 at 08:32 UTC
Settings
Get link