Textmate snippet: automatic get/set method pairs
I won't go into the details about why get/set methods are handy when doing object-oriented programming in general, but here's another TextMate snippet that should speed things up when using them in PHP5. Handles the tabbing and camelCasing of method names automatically:
See note below - this has formatting errors
public function set${1/./\u$0/}(\$$1) {
\$this->$1 = \$$1;
return true;
} // function set${1/./\u$0/}
${2:public function get${1/./\u$0/}() {
return \$this->$1;
\} // function get${1/./\u$0/}}
I have my snippet bound to "getset" (tab trigger) in textmate, so getset?body will yield the following:
public function setBody($body) {
$this->body = $body;
return true;
} // function setBody
public function getBody() {
return $this->body;
} // function getBody
I also have it configured so that tabbing a second time will highlight the entire getter method, in case you don't want it available for whatever reason (the code I'm writing has a big getAll-type method and individual getters would be highly redundant). Enjoy :)
Edit - sorry, something's screwing up the formatting here - I think it's being a little too aggressive with stripslashes() or something on display, as I see it properly in the editor window. See the attached screenshot of the snippet - keep an eye out for some extra backslashes escaping a few characters. Should be coming in a sec. Wordpress attachments hate me these days. Someday I'll do a proper reinstall and deal with all of the cruft.

