Menu

Error Identifier: return.internalTrait

← Back to return.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

namespace Vendor {
	/** @internal */
	trait InternalTrait {
		public function doSomething(): void {}
	}

	class Foo {
		use InternalTrait;
	}
}

namespace App {
	/** @return \Vendor\InternalTrait */
	function createObject() {
		return new \stdClass();
	}
}

Why is it reported? #

The return type of the function or method references a trait that is marked as @internal. Internal symbols are not meant to be used outside the package or namespace that defines them. Referencing an internal trait in a return type exposes an internal implementation detail in a public API, creating a dependency on something that may change without notice.

Traits should generally not be used as return types, since PHP does not support using traits as type hints.

How to fix it #

Replace the internal trait with a public interface or class in the return type:

 namespace App {
-	/** @return \Vendor\InternalTrait */
+	/** @return \Vendor\PublicInterface */
 	function createObject() {
 		return new \stdClass();
 	}
 }

If the trait is internal to the same package, the error will not be reported. The @internal restriction only applies to cross-package usage.

How to ignore this error #

You can use the identifier return.internalTrait to ignore this error using a comment:

// @phpstan-ignore return.internalTrait
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: return.internalTrait

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]
Theme
A
© 2026 PHPStan s.r.o.