Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate getter and setter in eclipse (php)

Tags:

php

eclipse

Usually, I use eclipse to work with Java, so when I want to work with PHP, I use eclipse too.

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.

How to do this with php in eclipse ?

Thanks.

like image 676
Kiva Avatar asked Nov 21 '10 13:11

Kiva


People also ask

Does PHP have getters and setters?

In this article, we learn the best way to create getter and setter strategies in PHP. Getter and setter strategies are utilized when we need to restrict the direct access to the variables by end-users. Getters and setters are methods used to define or retrieve the values of variables, normally private ones.

How do you use Lombok to create getters and setters?

Overview. You can annotate any field with @Getter and/or @Setter , to let lombok generate the default getter/setter automatically. A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type is boolean ).


3 Answers

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

And here's the gitub site.

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
like image 55
dcontard Avatar answered Oct 06 '22 01:10

dcontard


It seems like the E-surf plugin is 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

like image 43
Sean Patrick Floyd Avatar answered Oct 05 '22 23:10

Sean Patrick Floyd


A good answer is here: What is the best way to auto generate getters and setters for a class in php?

Create a template then you can use CTRL+Shift to execute it

private $$${PropertyName};
${cursor}    
public function get${PropertyName}() 
{
  return $$this->${PropertyName};
}

public function set${PropertyName}($$value) 
{
  $$this->${PropertyName} = $$value;
}

Thanks erisco for the great answer

like image 45
Alan B. Dee Avatar answered Oct 06 '22 01:10

Alan B. Dee