Menu

← Back to return.*

Error Identifier: return.internalClass

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 App;

// Defined in a third-party package:
// /** @internal */
// class InternalHelper {}

use ThirdParty\InternalHelper;

function createHelper(): InternalHelper
{
    // ...
}

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:

 <?php declare(strict_types = 1);
 
 namespace App;

-use ThirdParty\InternalHelper;
+use ThirdParty\HelperInterface;

-function createHelper(): InternalHelper
+function createHelper(): HelperInterface
 {
     // ...
 }

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]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.