Psalm
Get started
Documentation
Paid support
Plugins
Blog
GitHub
<?php declare(strict_types = 1); /** * @template TObj of object * @template TProp of string * @template TProps of properties-of<TObj> * * @param TObj $obj * @param TProp $prop * @return TProps[TProp] */ function getProp(object $obj, string $prop): mixed { assert(property_exists($obj, $prop)); return $obj->{$prop}; } class Example { function __construct(public string $foo) {} } function example(Example $example): string { return getProp($example, 'foo'); }
Snippet created on April 13 2024 at 12:39 UTC
Settings
Get link