<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 23 May 2012 05:47:53 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Josh Adell's Blog: GetSet Methods vs. Public Properties]]></title>
      <guid>http://www.phpdeveloper.org/news/17623</guid>
      <link>http://www.phpdeveloper.org/news/17623</link>
      <description><![CDATA[<p>
<i>Josh Adell</i> has a new post to his blog talking about a debate between developers over which is the better method - <a href="http://blog.everymansoftware.com/2012/03/getset-methods-vs-public-properties.html">using public properties or getters and setters</a> to work with values on your objects.
</p>
<blockquote>
I was recently having a debate with a coworker over the utility of writing getter and setter methods for protected properties of classes. On the one hand, having getters and setters seems like additional boilerplate and programming overhead for very little gain. On the other hand, exposing the value properties of a class seems like bad encapsulation and will overall lead to code that is more difficult to maintain. I come down firmly on the get/set method side of the fence. 
</blockquote>
<p>
In his opinion, the getter/setter method provides an explicit interface to the class that describes what it can do and how you can work with it. He gives code examples, comparing the two methods - simple setting of properties on one object and using get*/set* methods on the other. He brings up the point that, if ever in the future you wanted to handle the data for a property differently, say always make it an array or object. He also points out that this still doesn't prevent the setting of new properties directly, so he uses the magic __get and __set to deal with that.
</p>]]></description>
      <pubDate>Mon, 05 Mar 2012 09:50:21 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Rob Allen's Blog: Sublime Text 2 Snippet for PHP getter and setter generation]]></title>
      <guid>http://www.phpdeveloper.org/news/17336</guid>
      <link>http://www.phpdeveloper.org/news/17336</link>
      <description><![CDATA[<p>
In a quick new post to his blog, <i>Rob Allen</i> has <a href="http://akrabat.com/software/sublime-text-2-snippet-for-php-getter-and-setter-generation/">shared a snippet</a> for the Sublime Text 2 editor to make creating getters and setters for your class simpler (dynamically too).
</p>
<blockquote>
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.
</blockquote>
<p>
Included in the post is the code you'll need to put into the snippet - a simple find (regular expression based) looks at the currently selected variable and expands out the getter and setter for it. For more information on the Sublime Text 2 editor, see <a href="http://www.sublimetext.com/">the product's website</a>.
</p>]]></description>
      <pubDate>Tue, 03 Jan 2012 09:54:23 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Bence Eros' Blog: Getters, setters, performance]]></title>
      <guid>http://www.phpdeveloper.org/news/16580</guid>
      <link>http://www.phpdeveloper.org/news/16580</link>
      <description><![CDATA[<p>
<i>Bence Eros</i> has put together <a href="http://erosbence.blogspot.com/2011/07/getters-setters-performance.html">a new post to his blog</a> looking at some of the results he's found from performance testing the use of getters and setters in PHP.
</p>
<blockquote>
The usage of getter and setter methods instead of public attributes became very popular in the PHP community, and it's going to become the standard coding convention of so many PHP libraries and frameworks. On the other hand many developers - including me too - strongly unrecommend such convention, because of its performance overhead. I wanted to make some performance comparison for years, and today I had time to do that. In this post I would like to show what I found.
</blockquote>
<p>
He starts with a question every developer asks as their working in their application - why and when should they use getters and setters for their classes. He talks about using them as primary functionality or as fallbacks only when needed. He includes the simple benchmarking script he used to compare accessing/setting public attributes directly and using a getter/setter to do the same. The results aren't very surprising if you think about the "magic" that has to happen for getters and setters to work. See <a href="http://erosbence.blogspot.com/2011/07/getters-setters-performance.html">the rest of the post</a> for those numbers.
</p>]]></description>
      <pubDate>Tue, 12 Jul 2011 11:39:18 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Shawn Stratton's Blog: Accesors and Religion]]></title>
      <guid>http://www.phpdeveloper.org/news/16349</guid>
      <link>http://www.phpdeveloper.org/news/16349</link>
      <description><![CDATA[<p>
<i>Shawn Stratton</i> has a new post to his blog talking about a topic he calls "flame bait" - the use of <a href="http://www.shawnstratton.info/accesors-and-religion/">accessors in PHP applications</a> (getters and setters) to access class properties.
</p>
<blockquote>
Objects have prop­er­ties which some­times need spe­cial logic on how they are retrieved and set.  There are sev­eral solu­tions to this and every­body has a dif­fer­ent view point about which is cor­rect, none are pretty and all have draw­backs which range from writ­ing extra code, cre­at­ing some­thing that has poor exten­si­bil­ity, or has issues with con­sis­tency.  These don't even breach the issues with IDE code com­ple­tion and analy­sis.  Lets look at some of these solutions.
</blockquote>
<p>
The solutions are the direct access to the class properties (which can cause some painful inconsistencies when things get complicated) and the alternative of setting up getters/setters for everything. <i>Shawn</i>'s alternative makes use of the __get and __set magic methods to catch the property values being set and handle them correctly, developers being none the wiser.
</p>]]></description>
      <pubDate>Tue, 17 May 2011 14:46:32 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DZone.com: How to remove getters and setters]]></title>
      <guid>http://www.phpdeveloper.org/news/15951</guid>
      <link>http://www.phpdeveloper.org/news/15951</link>
      <description><![CDATA[<p>
On DZone.com's Web Builder Zone <i>Giorgio Sironi</i> has posted a few methods you can use to help <a href="http://css.dzone.com/articles/how-remove-getters-and-setters">get rid of getters and setters</a> in your OOP PHP applications.
</p>
<blockquote>
Encapsulation is (not only, but also) about being capable of changing private fields. If you write getters and setters, you introduce a leaky abstraction over private fields, since the names and number of your public methods are influenced coupled to them. They aren't really private anymore: 
</blockquote>
<p>
To show his alternatives, he uses a sample "User" class with a whole list of private properties. There's initially a get/set for the nickname and password values, but he suggests a few replacements:
</p>
<ul>
<li>passing values in through the constructor
<li>using the "Information Architect" pattern to have the most responsible method handle the value setting
<li>the "Double Dispatch" method that uses dependency injection
<li>using the Command pattern and changesets of data
</ul>
<p>
He also briefly mentions the Command-Query Responsibility Segregation (CQRS) method, but doesn't have any code example to go with it.
</p>]]></description>
      <pubDate>Wed, 23 Feb 2011 12:02:17 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Berry Langerak's Blog: Getters and setters: evil or necessary evil?]]></title>
      <guid>http://www.phpdeveloper.org/news/15898</guid>
      <link>http://www.phpdeveloper.org/news/15898</link>
      <description><![CDATA[<p>
In a new post <i>Berry Langerak</i> wonders if the getters and setters commonly used in PHP applications are a <a href="http://berryllium.nl/2011/02/getters-and-setters-evil-or-necessary-evil/">necessary evil</a> and if they should be used at all.
</p>
<blockquote>
Although I do still feel like getters and setters are to be avoided most of the time, it's hard to tell where to use them and where you shouldn't. [...] While writing the code for [PFZ.nl], I started to notice that each and every class in the system had accessors for most, if not all, protected fields. I've started a discussion with my fellow developers, and this is what I've argued.
</blockquote>
<p>
He mentions a few things including an article he'd written previously on the topic, some of the points behind OOP programming, encapsulation and accessors and collaborators. He also includes several code examples showing what he considers right and wrong ways to do thing (warning, opinions ahead).
</p>
<blockquote>
All in all, I don't think accessors are evil per se, but you should only ever use the accessors in cross-layer situations. Don't use accessors to build functionality, but only because you need the value to display and/or save.
</blockquote>]]></description>
      <pubDate>Mon, 14 Feb 2011 09:57:30 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Michael Kimsal's Blog: magic __get and __set style?]]></title>
      <guid>http://www.phpdeveloper.org/news/15608</guid>
      <link>http://www.phpdeveloper.org/news/15608</link>
      <description><![CDATA[<p>
In <a href="http://michaelkimsal.com/blog/magic-__get-and-__set-style/">this recent post</a> to his blog <i>Michael Kimsal</i> asked about the usefulness of the __get and __set magic methods and the sort of code he usually sees along with it.
</p>
<blockquote>
For a long time I've held that __get and __set in PHP were not all that hot  - mostly because it's solely error handling.  There's no way to deal invoke __get or __set behaviour for properties that are defined on a class. [...] For those who insist on using __get/__set, I *typically* see this [messyy] sort of style code. The effect is to cram a bunch of unrelated code in to the __get/__set overloading methods.
</blockquote>
<p>
He suggests an alternative to the "cram it all in __get" approach - callbacks to other methods in the class to handle the different variable possibilities. In the comments there's other suggestions on how to get the same job done differently - mapping property values with __call, valid uses for getters/setters and a pointer to <a href="http://wiki.php.net/rfc/propertygetsetsyntax">an internals discussion RFC</a> about this same thing. 
</p>]]></description>
      <pubDate>Tue, 21 Dec 2010 09:36:05 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Adam Jensen's Blog: Output Transformation in a Zend Framework Model Layer]]></title>
      <guid>http://www.phpdeveloper.org/news/12285</guid>
      <link>http://www.phpdeveloper.org/news/12285</link>
      <description><![CDATA[<p>
<i>Adam Jensen</i> has <a href="http://jazzslider.wordpress.com/2009/04/06/output-transformation-in-a-zend-framework-model-layer/">a new post</a> to his blog today looking at a solution he's created to be able to access the raw input a user has entered.
</p>
<blockquote>
I've run into a minor problem, and I'm not sure my solution is particularly ideal. See, the Zend_Form approach described above does a great job of implementing Chris Shiflett's <a href="http://shiflett.org/blog/2005/feb/my-top-two-php-security-practices">Filter Input, Escape Output</a> principle...user input is filtered for invalid HTML before it's ever saved to the model, and can then be escaped as appropriate in the view layer. But what happens if you need to be able to retrieve the user's original unfiltered input later?
</blockquote>
<p>
While working with the raw data could be dangerous, he has created a custom model that, through the getters and setters and doing validation/sanitization and the presentation layer rather than behind the scenes. It's not ideal but he's <a href="http://jazzslider.wordpress.com/2009/04/06/output-transformation-in-a-zend-framework-model-layer/#comments">willing to take suggestions</a>...
</p>]]></description>
      <pubDate>Mon, 06 Apr 2009 13:43:06 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jani Hartikainen's Blog:  Creating a simple abstract model to reduce boilerplate code]]></title>
      <guid>http://www.phpdeveloper.org/news/12046</guid>
      <link>http://www.phpdeveloper.org/news/12046</link>
      <description><![CDATA[<p>
In <a href="http://codeutopia.net/blog/2009/02/28/creating-a-simple-abstract-model-to-reduce-boilerplate-code/">a new blog post</a> <i>Jani Hartikainen</i> shows how to create an abstract model that you can build on when you need to make a dynamic model for your framework application.
</p>
<blockquote>
In a usual scenario involving models in PHP, you will have some repeating things: You will usually need getters and setters for the model's properties, you will need to be able to construct the model from an SQL query or such, and you'll also need to write SQL queries for the models.
</blockquote>
<p>
He builds up the three different parts of the abstract model - the getters/setters, fleshing out the model by defining its properties from array values and creating some dynamic SQL (based on property names).
</p>]]></description>
      <pubDate>Mon, 02 Mar 2009 12:07:54 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPImpact Blog: No need for set/get methods in Python]]></title>
      <guid>http://www.phpdeveloper.org/news/10849</guid>
      <link>http://www.phpdeveloper.org/news/10849</link>
      <description><![CDATA[<p>
<i>Federico</i> <a href="http://phpimpact.wordpress.com/2008/08/17/no-need-for-setget-methods-in-python/">compares two languages</a> in this new post to the PHP::Impact blog today - PHP and Python - in their need for "getters" and "setters".
</p>
<blockquote>
Python code doesn't typically use the get and set methods so common in PHP. Normally, when writing PHP code, you carefully protect your instance variables by making them private, so callers can only interact with them via getter and setter methods. [...] Python's solution to this problem is more readable, it has a construct called a "property".
</blockquote>
<p>
He compares two blocks of code that do the same thing - set properties on the object with the PHP side doing a bit more error checking (seemingly) than the Python side. They both apply a title property to a book object.
</p>]]></description>
      <pubDate>Mon, 18 Aug 2008 12:06:37 -0500</pubDate>
    </item>
  </channel>
</rss>

