Error Identifier: class.extendsInternalClass
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);
// Assuming SomeLibrary\InternalBase is marked @internal
class MyClass extends \SomeLibrary\InternalBase
{
}
Why is it reported? #
The class extends another class that is marked as @internal by its declaring library. Internal classes are implementation details not meant to be extended by external code. The library may change, rename, or remove internal classes without notice, which would break any code that extends them.
How to fix it #
Extend a public base class provided by the library instead:
<?php declare(strict_types = 1);
-class MyClass extends \SomeLibrary\InternalBase
+class MyClass extends \SomeLibrary\PublicBase
{
}
Or implement a public interface instead of extending the internal class:
<?php declare(strict_types = 1);
-class MyClass extends \SomeLibrary\InternalBase
+class MyClass implements \SomeLibrary\PublicInterface
{
}
How to ignore this error #
You can use the identifier class.extendsInternalClass to ignore this error using a comment:
// @phpstan-ignore class.extendsInternalClass
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: class.extendsInternalClass
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]