如何在PhpStorm的类构造函数中自动生成参数分配? [英] How to automatically generate parameter assignations in class constructors in PhpStorm?

查看:325
本文介绍了如何在PhpStorm的类构造函数中自动生成参数分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建类构造函数并将所有参数分配给相应的类字段时,有人知道如何在PhpStorm中保存键入吗?我现在手动编写它,并且可以使用自动完成功能快速完成它,但这仍然是一个非常繁琐的过程.

Does anyone know how to save typing in PhpStorm when you create a class constructor and you want to assign all the parameters to the respective class fields? I write it by hand now and I can do it quite quickly with the autocomplete feature, yet it is still a very tedious process.

例如:

class Foo
{
    private $param1; 
    private $param2;
    private $param3;    

    public function __construct($param1, $param2, $param3) {
          // Can I somehow automatically generate the following lines:
          //
          // $this->param1 = $param1;
          // $this->param2 = $param2;
          // $this->param3 = $param3;
          //
          //?
    }      
}

推荐答案

使用初始化字段" 意图.为此:将插入符号放在参数之一上,然后调用QuickFix菜单( Alt + Enter 或通过单击灯泡图标).

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).

这篇关于如何在PhpStorm的类构造函数中自动生成参数分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆