Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Sublime Text 2 Snippet for PHP getter and setter generation

DZone's Guide to

Sublime Text 2 Snippet for PHP getter and setter generation

· Web Dev Zone
Free Resource

Try RAD Studio for FREE!  It’s the fastest way to develop cross-platform Native Apps with flexible Cloud services and broad IoT connectivity. Start Your Trial Today!

I've been playing with Sublime Text 2 recently and have quite enjoyed how quiet my ageing laptop is when the fans aren't running due to a Java-based IDE.

As with a lot of editors, Sublime Text supports snippets which are essentially text expansions of a short phrase into more text. I needed to create a few getXxx() and setXxx() methods for some properties of a class and decided that the easiest way to do this would be with a snippet.

To create a snippet, go to Tools->New Snippet... and replace the code example provided with this:

<snippet>
    <content><![CDATA[public function get${1/(.*)/u$1/}()
{
    return $this->${1:$SELECTION};
}

public function set${1/(.*)/u$1/}($$1)
{
    $this->$1 = $$1;
    return $this;
}
]]></content>
    <!-- Optional: Tab trigger to activate the snippet -->
    <tabTrigger>getset</tabTrigger>
    <!-- Optional: Scope the tab trigger will be active in -->
    <scope>source.php</scope>
    <!-- Optional: Description to show in the menu -->
    <description>Create getter and setter methods</description>
</snippet>

Save the file as getset.sublime-snippet and you're done.

To use, simply type getset followed by tab (in the latest dev builds, at least) and it will automatically expand. Alternatively, select some text and use shift+cmd+p -> getset to automatically replace the selected text with the get and set methods completed for the text that was selected.

 

Source: http://akrabat.com/software/sublime-text-2-snippet-for-php-getter-and-setter-generation/

 

Get Your Apps to Customers 5X Faster with RAD Studio. Brought to you in partnership with Embarcadero.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}