3 abstract class BaseField
<T
> {
5 final public function __construct() {}
7 final public static function fromType($type): this
{
8 $class_name = $type->getClassName();
9 $field = new $class_name();
12 $field instanceof static,
13 '%s is not a valid %s',
19 if ($type instanceof HasFoo
) {
20 // This illustrates a limitation of the typechecker:
21 // - intersection of this<BaseField> and INeedsFoo
23 $field instanceof INeedsFoo
,
24 'The context arg was provided, but the field doesn\'t support one',
27 $field->setFoo($type->getFoo());
35 interface INeedsFoo
<T
> {
38 public function setFoo(T
$arg): this
;