How to automatically generate parameter assignations in class constructors in PhpStorm?

Use "Initialize fields" intention. For that: place caret on one of the parameters and invoke QuickFix menu (Alt + Enter or by clicking on light bulb icon).

enter image description here


In case you want to have PhpStorm generate the constructor too you can go to Code -> Generate -> Constructor. This will take care of inserting the parameters you want as well as their initialization.

Or press Alt+Insert and choose Constructor...


If you move the cursor to the word '__constructor', within a second or two a lightbulb pops up. when you press it you get an option "Initialize properties". If you select that option a popup appears where you can specify for which argument you want to create and assign a property.

[Lightbulb[1]] Argument popup

Tags:

Php

Phpstorm