Generics
A generic class lets you choose the type of value it works with. In Box<T>, T is a type parameter: use Box<string> to hold a string or Box<int> to hold an integer. The same class handles both, and reading $box->value gives you the type you chose:
Box.ppphp
final class Box<T>
{
public function __construct(
public readonly T $value,
) {}
}
Press Run to print the string stored in the box. Then replace the line that creates it with an integer box:
Box.ppphp
Box<int> $box = new Box(42);
Run again to print 42. Try passing a string to Box<int> and press Check to see the mismatch. Build PHP shows one ordinary PHP class with @template PHPDoc, so your PHP tools can understand the type relationship too.