Menu

Error Identifier: return.internalClass

← 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 */
	class InternalResult {}
}

namespace App {
	function getResult(): \Vendor\InternalResult {
		return new \Vendor\InternalResult();
	}
}

Why is it reported? #

The native return type declaration of a function or method references a class that is marked as @internal. Internal classes are not part of the public API of the package that defines them. Using an internal class in a return type exposes an implementation detail to callers, creating a dependency on something that may change or be removed without notice.

How to fix it #

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

 namespace App {
-	function getResult(): \Vendor\InternalResult {
-		return new \Vendor\InternalResult();
+	function getResult(): \Vendor\ResultInterface {
+		// ...
 	}
 }

If the class 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.internalClass to ignore this error using a comment:

// @phpstan-ignore return.internalClass
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.internalClass

Rules that report this error #

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