jEdit Community - Resources for users of the jEdit Text Editor
PHP getter/setter macro
Submitted by stavros on Thursday, 7 October, 2004 - 16:53
Hey Folks. Over the weekend I started working on a new project and was laying the infrastructure/groundwork out for everything .. doing up the class libs and what not .. I used DB_DataObject a lot in the past to generate my db class object code, but I decided to use my own rolled DbObject class and found myself writting millions of getters/setters for my class files.
Anyway, I got bored of that and found a macro someone wrote (and is posted somewhere on the site) which generates getters/setters for a c or java file and figured, what the heck, let's tweak that for php.

So I did ... and have it working for me somehow ok .. you just highlite the vars, run the macro and it whips them out, you can even select to use javadoc style comments or not.
The original author did a great job, kudos to him/her, wherever they are ... if anyone is interested in using this hacked-for-php version, I can post it somewhere here .. there are a few idiosincrosies I guess that make it work the way I work, but it's a start at least. For instance, for some reason I my db variables/columns use_this_approach to var naming ... when I code, I use studlyCaps, so my class files look like this.

class Something {
    protected $first_var; // <-- this is how it's named in the db

    // and the getter/setter for that looks like
    // {{{ Getters

    /**
     * javadoc
     */
    public function getFirstVar($first_var) {
          $this->first_var = $first_var;
    }

    // }}} End Getters

    // {{{ Setters
    
    /**
     * javadoc
     */
    public function getFirstVar() {
          return $this->first_var;
    } 

    // }}} End setters

} // class



hah ... interesting, eh? Don't know why I do that, but anyway ... that's how "my" .bsh macro does the getters/setters, but you can hack it pretty easily to work like you do (in a php4 style too, if necessary)... there's more work to be done to make the macro more helpful/slick but if anyone might find it helpful for now, I'll throw her up somewhere ...
-steve
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Here's the macro
by stavros on Thu, 28/10/2004 - 18:41
I posted the macro up here .. it's still a work in progress, but you might find it helpful even before it's "complete" Smiling

You can find brief instructions and the macro here
oops
by stavros on Thu, 07/10/2004 - 16:59
heh .. that was dumb .. screwed the pooch on that post.
the getter looks like
public function getFirstVar() {
    return $this->first_var;
}

// and the setter looks like
public function setFirstVar($first_var) {
    $this->first_var = $first_var;
}


I think that's right now Smiling
-steve
 
Yes Please
by Anonymous on Tue, 12/10/2004 - 08:27
BTW I do my gets and sets exactly like that, thanks in advance.
User login
Browse archives
« November 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300