website/errors/requireImplements.nonObject.md
<?php declare(strict_types = 1);
/**
* @phpstan-require-implements int
*/
trait MyTrait // ERROR: PHPDoc tag @phpstan-require-implements contains non-object type int.
{
}
The @phpstan-require-implements PHPDoc tag must reference an interface (object) type. Scalar types like int, string, bool, union types, or other non-object types cannot be implemented by a class and are therefore not valid in this tag.
Replace the non-object type with an interface:
<?php declare(strict_types = 1);
+interface Countable
+{
+ public function count(): int;
+}
+
/**
- * @phpstan-require-implements int
+ * @phpstan-require-implements Countable
*/
trait MyTrait
{
}
If the requirement is about a specific type constraint that is not an interface, consider whether @phpstan-require-extends (for classes) or another mechanism is more appropriate.