Menu

← Back to class.*

Error Identifier: class.extendsNetteObject

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 Nette\LegacyObject;

class MyPresenter extends LegacyObject
{
}

Why is it reported? #

The Nette\Object and Nette\LegacyObject base classes are deprecated in the Nette framework. Extending them is no longer recommended. The modern approach is to use the Nette\SmartObject trait instead, which provides the same magic functionality (property accessors, event support) without requiring class inheritance.

How to fix it #

Replace the base class with the Nette\SmartObject trait:

 <?php declare(strict_types = 1);
 
-use Nette\LegacyObject;
+use Nette\SmartObject;

-class MyPresenter extends LegacyObject
+class MyPresenter
 {
+	use SmartObject;
 }

How to ignore this error #

You can use the identifier class.extendsNetteObject to ignore this error using a comment:

// @phpstan-ignore class.extendsNetteObject
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.extendsNetteObject

Rules that report this error #

  • PHPStan\Rule\Nette\DoNotExtendNetteObjectRule [1] phpstan/phpstan-nette

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.