Inspectopedia 2024.3 Help

Old style constructor

Reports old-style constructor declarations (ClassName()) and suggests replacing them with new-style constructors (__construct()).

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

PhpConstructorStyleInspection
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | PHP | Code style

Prior to PHP 8.0, old-style constructor syntax used in the classes in the global namespace is treated as deprecated and will result in an E_DEPRECATED error. If both a __construct() and a ClassName() method are defined, __construct() will be called.

In namespaced classes, or any classes as of PHP 8.0, a ClassName() method never has any special meaning and will never be called as a constructor. As a result, the inspection does not report such cases if the PHP language level is set to 8.0 or later.

See Constructors and destructors (php.net) for details.

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.3, PhpStorm 2024.3, Qodana for JVM 2024.3, Qodana for PHP 2024.3,

Can be installed with plugin:

PHP, 243.23126

Last modified: 03 December 2024