Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<snippet>
<content><![CDATA[public function get${1/(.*)/\u$1/}()
{
return \$this->${1:$SELECTION};
}
public function set${1/(.*)/\u$1/}(\$$1)
{
return \$this->$1 = \$$1;
}
]]></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>
@rogeriopradoj

This comment has been minimized.

Copy link

rogeriopradoj commented Apr 1, 2012

Olá Eminetto.

O que você acha de alterar os setters para um estilo method chaining?

Talvez assim:

// ...
public function set${1/(.*)/\u$1/}($$1)
{
$this->$1 = $$1;
return $this;
}
// ...

@eminetto

This comment has been minimized.

Copy link
Owner Author

eminetto commented Apr 2, 2012

É uma boa alternativa Rogério

@rogeriopradoj

This comment has been minimized.

Copy link

rogeriopradoj commented Apr 4, 2012

Cara, criei um fork, vou fazer propaganda aqui: https://gist.github.com/2289328.

Dúvida: sei que deve depender de projeto para projeto, e mais ainda de classe para classe, mas como vocês costumam fazer os getters e setters na http://www.coderockr.com/ ?

Usam method chaining?

@eminetto

This comment has been minimized.

Copy link
Owner Author

eminetto commented Apr 5, 2012

Geralmente não usamos method chaining. Acho que mais por vício do que por qualquer coisa :)

@wellfreire

This comment has been minimized.

Copy link

wellfreire commented Nov 13, 2013

2 anos depois...muito bom meu caro @rogeriopradoj!

@pegnacorp

This comment has been minimized.

Copy link

pegnacorp commented Apr 3, 2015

Muy bueno 😄

@luancschmitz

This comment has been minimized.

Copy link

luancschmitz commented Aug 21, 2015

muito obrigado mesmo..funciona tranquilo no Sublime text 3. Me ajudou muito

@bsoliveira

This comment has been minimized.

Copy link

bsoliveira commented Oct 12, 2015

Isso é coisa linda de Deus! Obrigado por compartilhar!

@flavio-ever

This comment has been minimized.

Copy link

flavio-ever commented Dec 2, 2017

Agraço muito! Isso me salvou da chatice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.