如何在eclipse(php)中生成getter和setter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4238174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate getter and setter in eclipse (php)
提问by Kiva
Usually, I use eclipse to work with Java, so when I want to work with PHP, I use eclipse too.
通常,我使用 eclipse 来处理 Java,所以当我想使用 PHP 时,我也使用 eclipse。
But I don't know how to generate getter and setter for class variables. When I do a right click, I don't have the menu Source -> Generate Getter / Setter
.
但我不知道如何为类变量生成 getter 和 setter。当我右键单击时,我没有 menu Source -> Generate Getter / Setter
。
How to do this with php in eclipse ?
如何在 eclipse 中用 php 做到这一点?
Thanks.
谢谢。
采纳答案by jgxvx
Zend Studio, which is based on Eclipse, provides this feature as well. It is not free, however, but if you don't mind paying for an IDE, this might be an option.
基于 Eclipse 的 Zend Studio 也提供了此功能。然而,它不是免费的,但如果您不介意为 IDE 付费,这可能是一个选择。
If you're currently using PHP, you might find this comparison between PDT and Zend Studio useful:
如果您目前正在使用 PHP,您可能会发现 PDT 和 Zend Studio 之间的这种比较很有用:
回答by dcontard
I was looking for something similar to these two alternatives. I found one that is free and seems to be updated regularly, so I'm leaving the link here for others to come: PDT Extensions(and the snapshotversion).
我正在寻找类似于这两种选择的东西。我找到了一个免费的并且似乎定期更新,所以我将链接留在这里供其他人使用:PDT 扩展(和快照版本)。
And here's the gitubsite.
这是gitub站点。
Addons for the eclipse PHP development tools. Provides code formatting and code generation like
- getter/setter generation
- new class wizard
- interface method implementation
- and other features
Eclipse PHP 开发工具的插件。提供代码格式化和代码生成,如
- getter/setter 生成
- 新班级向导
- 接口方法实现
- 和其他功能
回答by Sean Patrick Floyd
It seems like the E-surf pluginis what you need. From the features page:
The main features added in 1.0.0 (current) version:
- Possibility to handle multiple PHP classes in one source file
- Additional generated methods sort mode (first setters, then getters)
- Improved main menu access - only when a suitable PHP editor is available
1.0.0(当前)版本中添加的主要功能:
- 可以在一个源文件中处理多个 PHP 类
- 其他生成的方法排序模式(首先是 setter,然后是 getter)
- 改进了主菜单访问 - 仅当合适的 PHP 编辑器是可用的
回答by Alan B. Dee
A good answer is here: What is the best way to auto generate getters and setters for a class in php?
一个很好的答案在这里:在 php 中为类自动生成 getter 和 setter 的最佳方法是什么?
Create a template then you can use CTRL+Shift to execute it
创建一个模板,然后你可以使用 CTRL+Shift 来执行它
private $$${PropertyName};
${cursor}
public function get${PropertyName}()
{
return $$this->${PropertyName};
}
public function set${PropertyName}($$value)
{
$$this->${PropertyName} = $$value;
}
Thanks erisco for the great answer
感谢 erisco 的精彩回答
回答by alexjosesilva
This can help, it is a plugin to generate code in PHP. http://pdt.plugins.e-surf.pl/install.php
这可以提供帮助,它是一个在 PHP 中生成代码的插件。 http://pdt.plugins.e-surf.pl/install.php
回答by Norkos
I found this Plugin very useful: http://loge5.de/phpgen
我发现这个插件非常有用:http: //loge5.de/phpgen
It supports comments, "Fluid Interface" and some other stuff. Quite simple and clear but more powerful than the E-Surfplugin.
它支持注释、“流体界面”和其他一些东西。非常简单明了,但比 E-Surf插件更强大。
回答by ozzy432836
I know what you wanted cos I was exactly the same scenario... learnt Java in Eclipse then moved to other languages and missed that feature so I wrote this in PHP. So you don't have to change editors just to get that one feature. It also works for VB as that was what I originally created it for...
我知道你想要什么,因为我是完全相同的场景……在 Eclipse 中学习了 Java,然后转移到其他语言并错过了该功能,所以我用 PHP 编写了这个。因此,您不必为了获得该功能而更改编辑器。它也适用于 VB,因为那是我最初为...
You can download it here: https://github.com/aosiname/Generate-Getters-and-Setters
你可以在这里下载:https: //github.com/aosiname/Generate-Getters-and-Setters
回答by CodeBird
it is a bit late to answer this question, but I was searching for this today and found out a plugin that could be installed from eclipse URL: http://pdt.plugins.e-surf.pl/updates/
回答这个问题有点晚了,但我今天正在搜索这个并发现了一个可以从 eclipse URL 安装的插件:http: //pdt.plugins.e-surf.pl/updates/