Menu

← Back to catch.*

Error Identifier: catch.internalEnum

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

// In package vendor/some-library:

namespace SomeLibrary;

/** @internal */
enum ErrorCode: int
{
	case NotFound = 404;
	case ServerError = 500;
}
<?php declare(strict_types = 1);

// In your code:

namespace App;

use SomeLibrary\ErrorCode;

try {
	// ...
} catch (ErrorCode $e) {
	// ...
}

Why is it reported? #

A catch block references an enum that is marked as @internal. Internal types are not meant to be used outside of the package or namespace where they are defined. Catching internal enums creates a dependency on implementation details that may change without notice in future versions.

How to fix it #

Catch a public (non-internal) exception class instead:

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

-use SomeLibrary\ErrorCode;

 try {
 	// ...
-} catch (ErrorCode $e) {
+} catch (\RuntimeException $e) {
 	// ...
 }

If the library provides a public exception class or interface for this purpose, catch that instead.

How to ignore this error #

You can use the identifier catch.internalEnum to ignore this error using a comment:

// @phpstan-ignore catch.internalEnum
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: catch.internalEnum

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.