Menu

← Back to new.*

Error Identifier: new.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;

// Assume InternalHelper is marked @internal in vendor/some-package

$helper = new \Vendor\InternalHelper(); // error: Instantiation of internal class Vendor\InternalHelper.

Why is it reported? #

The class being instantiated is marked as @internal, meaning it is not part of the package’s public API. Internal classes may change or be removed in any release without following semantic versioning. Using them from outside the package creates fragile dependencies that can break without warning during updates.

How to fix it #

Use the public API provided by the package instead of instantiating its internal classes directly.

-$helper = new \Vendor\InternalHelper();
+$helper = \Vendor\HelperFactory::create();

If no public alternative exists, consider opening a feature request with the package maintainer.

How to ignore this error #

You can use the identifier new.internalClass to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.