Menu

← Back to phpstanApi.*

Error Identifier: phpstanApi.constructor

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

use PHPStan\Type\StringType;

// Inside a PHPStan extension
$type = new StringType();

Why is it reported? #

This error is reported when code instantiates a PHPStan internal class whose constructor is not covered by the backward compatibility promise. PHPStan reserves the right to change the constructor signature of such classes in minor versions, which could break extensions that directly instantiate them.

Only classes with @api on their constructor are guaranteed to have a stable constructor signature across minor releases.

How to fix it #

Check whether the class has a factory method or service that is part of the public API. In many cases, PHPStan provides @api-annotated factory methods or the class should be obtained through the dependency injection container rather than instantiated directly.

If the class genuinely needs to be instantiated and the constructor is not marked as @api, open a discussion at github.com/phpstan/phpstan/discussions to request that it be covered by the backward compatibility promise.

How to ignore this error #

You can use the identifier phpstanApi.constructor to ignore this error using a comment:

// @phpstan-ignore phpstanApi.constructor
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: phpstanApi.constructor

Rules that report this error #

  • PHPStan\Rules\Api\ApiInstantiationRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.