# UnsafeGenericInstantiation Emitted when an attempt is made to instantiate a class using `new static` without a constructor that's final: ```php t = $t; } /** * @template U * @param U $u * @return static */ public function getInstance($u) : static { return new static($u); } } ``` ## What’s wrong here? The problem comes when extending the class: ```php t = $t; } /** * @template U * @param U $u * @return static */ public function getInstance($u) : static { return new static($u); } } /** * @extends Container */ class StringContainer extends Container {} $c = StringContainer::getInstance(new stdClass()); // creates StringContainer, clearly invalid ``` ## How to fix Either use `new self` instead of `new static`: ```php t = $t; } /** * @template U * @param U $u * @return self */ public function getInstance($u) : self { return new self($u); } } ``` Or you can add a `@psalm-consistent-templates` annotation which ensures that any child class has the same generic params: ```php t = $t; } /** * @template U * @param U $u * @return static */ public function getInstance($u) : static { return new static($u); } } /** * @template T * @psalm-extends Container */ class LazyLoadingContainer extends Container {} ```