DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Sublime Text 2 Snippet for PHP getter and setter generation

Sublime Text 2 Snippet for PHP getter and setter generation

Rob Allen user avatar by
Rob Allen
·
Jan. 04, 12 · Web Dev Zone · Interview
Like (0)
Save
Tweet
6.88K Views

Join the DZone community and get the full member experience.

Join For Free

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/

 

Sublime Text PHP Snippet (programming)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • C++ Creator Bjarne Stroustrup Interview
  • The Importance of Semantics for Data Lakehouses
  • Streaming ETL with Apache Kafka in the Healthcare Industry
  • Implementing Microservices Architectures

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo