- assert: documentation ( source)
<?php
/**
* @template T of int|numeric-string
*/
class Foo
{
/** @param T $bar */
public function __construct(public $bar) {}
}
function bar(Foo $foo): void
{
$foo->bar = 123;
}
/** @var Foo<numeric-string> $foo */
$foo = new Foo("123");
bar($foo);
assert(is_string($foo->bar));