My Little Corner of the Net

Generate Accessors and Mutators Automatically with PDT

I’ve been using PDT, the PHP Development Tools IDE that’s built on top of Eclipse, for my PHP development for a few years now. I came to appreciate the power and flexibility of Eclipse as a Java IDE, so it only made sense to use PDT for my PHP coding.

One thing that’s always frustrated me about PDT, however, is that there is no way to auto-generate accessors and mutators (also called getters and setters) in classes. I do a lot of Active Record style database interactions, with classes that have lots of properties, and I always find it frustrating to write all of the get*() and set*() functions by hand.

I recently discovered the PHP Source Plugin for PDT, which does exactly what I want. With a simple menu click, I get a dialog box that lists all of my class’ properties. With a couple more clicks, I can specify wich of those properties should have accessors and/or mutators, and then the plugin g creates the code. All I have to do is go in and add validation code and PHPDOC comments, and I can move on to the next class. This is going to be a HUGE time saver.

PHP Source Plugin in published by E-surf. The fastest way to install it is to use their Eclipse update site, which is available at

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>