Ken*_*hvr 11 php eclipse get class set
我经常创建一个包含一些私有变量的类.设置此类的实例时,应该可以使用getter和setter填充类的所有变量.
是否有一种简单的方法可以在创建类时不必为每个变量键入所有这些setter和getter?
现在我必须为类中的每个var键入这个
public function setVar($var){
$this->var = $var;
}
Run Code Online (Sandbox Code Playgroud)
和
public function getVar(){
return $this->var;
}
Run Code Online (Sandbox Code Playgroud)
我们现在使用RegExp,但我不知道这是否是最简单的方法...我们使用Eclipse作为环境,所以也许有一些有用的插件?
eri*_*sco 33
使用Eclipse转到Preferences - > PHP - > Editor - > Templates - > New并使用以下内容:
private $$${PropertyName};
${cursor}
public function get${PropertyName}()
{
return $$this->${PropertyName};
}
public function set${PropertyName}($$value)
{
$$this->${PropertyName} = $$value;
}
Run Code Online (Sandbox Code Playgroud)
要使用模板键入它的名称并按ctrl + space - 键入名称时也应自动显示上下文菜单.