3

Is there a shortcut in PhpStorm to generate code for $model2 same as $model1?

class Test{    
    private $model1;
    public function __construct(string $model1, $model2)
    {
       $this->model1 = $model1;
       ....          
    }
}
LazyOne
  • 158,824
  • 45
  • 388
  • 391
SexyMF
  • 10,657
  • 33
  • 102
  • 206

3 Answers3

5
  1. Place caret on __construct or inside its' parameters .. and invoke Quick Fix menu (Alt + Enter or via light bulb icon).

  2. Choose appropriate option there -- it will be Initialize fields

enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
2

Yes, place cursor on $model2, then press Alt+Enter and choose option Initialize fields.

It will create a private field in your class (if it doesn't exists yet), and assign it inside constructor.

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
0

You can initialize and create __construct method by shortcut

Place your cursor where you want to create __construct method then press ALT + Insert Select constructor and choose your propertise