<?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>Fri, 29 Aug 2008 19:19:44 -0500</pubDate>
    <ttl>30</ttl>
    <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>
    <item>
      <title><![CDATA[Lars Strojny's Blog: Antipattern: the verbose constructor]]></title>
      <guid>http://www.phpdeveloper.org/news/10726</guid>
      <link>http://www.phpdeveloper.org/news/10726</link>
      <description><![CDATA[<p>
In <a href="http://usrportage.de/archives/897-Antipattern-the-verbose-constructor.html">this new post</a> from <i>Lars Strojny</i>, there's a discussion of an "antipattern" - using the constructor for more than it was intended, the "verbose constructor".
</p>
<blockquote>
Constructors are often used to shortcut dependency injection and parameter passing on instantiation. This is a valid practice and often leads to shorter code. [...] Instead of creating a new instance of "Money" and calling three setter, everything can be done compactly in the constructor. [...] So for the money object this works pretty well. The code is easy to read, but wait, the first argument can be grasped easily, the second too, but the third? It is not too obvious that it is a divisor is passed.
</blockquote>
<p>
He compares three different ways to get the data into the class - the already-mentioned parameters in the constructor, passing an array into the constructor and using full getters/setters to push the data into the right places (with fluent interfaces even!). 
</p>]]></description>
      <pubDate>Thu, 31 Jul 2008 10:29:14 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Debuggable Blog: Programming Psychology II: Private methods ]]></title>
      <guid>http://www.phpdeveloper.org/news/10560</guid>
      <link>http://www.phpdeveloper.org/news/10560</link>
      <description><![CDATA[<p>
According to <i>Felix Geisendorfer</i>'s <a href="http://www.debuggable.com/posts/programming-psychology-ii-private-methods:481ed862-b0d8-4a0e-9247-165c4834cda3">newest post</a> on the Debuggable blog, he thinks that "private and protected methods and properties are one of the most stupid concepts of OOP."
</p>
<blockquote>
This is a thought I first shared at <a href="http://debuggable.com/posts/cakefest-orlando-2008-summary:480f4dd6-6404-4774-a771-4e8fcbdd56cb">CakeFest Orlando</a> this year, but could not explain properly at the time.
</blockquote>
<p>
He illustrates with an example of a protected "balance" variable in a BankAccount class. Sure, it's marked as private but less skilled programmers might not use it that way. He recommends a method without the getters/setters to help make the usage of the variable a bit simpler. He also suggests that using protected/private scoping helps to promote "crappy code" - using them to provide a sort of protection for code that you either don't want getting used or hiding it away so the API can't get at it.
</p>]]></description>
      <pubDate>Tue, 08 Jul 2008 08:44:58 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Utilizing Private Methods with PHP 5 and Member Visibility ]]></title>
      <guid>http://www.phpdeveloper.org/news/10437</guid>
      <link>http://www.phpdeveloper.org/news/10437</link>
      <description><![CDATA[<p>
DevShed has posted the <a href="http://www.devshed.com/c/a/PHP/Utilizing-Private-Methods-with-PHP-5-and-Member-Visibility/">fifth part</a> of their series looking at the visibility keywords on PHP5's object oriented support today. They've already looked at <a href="http://www.phpdeveloper.org/news/10292">private</a>, <a href="http://www.phpdeveloper.org/news/10394">public</a> and <a href="http://www.phpdeveloper.org/news/10292">protected</a> properties in a class, now they look at the use of making methods private to restrict their use/extension.
</p>
<blockquote>
Of course, when it comes to specifying how visible a certain class property or method will be, you know that PHP 5 permits you to work with three distinct levels of access, called "public," "protected," and "private" respectively. [...] As you may have noticed, however, I've not taught you how to define private methods yet, which is something that can definitely be very useful if you want to restrict the access to your classes from the outside more severely.
</blockquote>
<p>
The <a href="http://www.devshed.com/c/a/PHP/Utilizing-Private-Methods-with-PHP-5-and-Member-Visibility/">tutorial</a> shows the creation of a class with private properties and then expands it to include a private method. Then they call it from an object, an example of the error PHP kicks back is there too. He also includes the concept of a "getter" to call the private function from a public one.
</p>]]></description>
      <pubDate>Thu, 19 Jun 2008 07:58:51 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Alex Netkachov's Blog: Are setters evil?]]></title>
      <guid>http://www.phpdeveloper.org/news/10425</guid>
      <link>http://www.phpdeveloper.org/news/10425</link>
      <description><![CDATA[<p>
<i>Alex Netkachov</i> has posted his <a href="http://www.alexatnet.com/node/151">own response</a> to <a href="http://www.phpdeveloper.org/news/10420">this opinion</a> on the Typical Programmer on getters and setters in object-oriented applications.
</p>
<blockquote>
"Do not use getters and setters" looks like a hastily advise, but its meaning is very important and it is "do not break encapsulation", which moves us to the question what the encapsulation is.
</blockquote>
<p>
He notes that encapsulation is, in essence, hiding parts of the code away so that the user/other coders only see a little bit of the magic that happens. He argues that getters and setters are a valid part of the encapsulation process and that designing a good, easy to use system almost requires them.
</p>]]></description>
      <pubDate>Tue, 17 Jun 2008 09:36:03 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Typical Programmer Blog: Doing it wrong: getters and setters]]></title>
      <guid>http://www.phpdeveloper.org/news/10420</guid>
      <link>http://www.phpdeveloper.org/news/10420</link>
      <description><![CDATA[<p>
According to <a href="http://typicalprogrammer.com/?p=23">this new post</a> on the Typical Programmer blog, using getters and setters in your scripts only adds in a bit of unnecessary coupling and complexity to your scripts that you just don't need.
</p>
<blockquote>
Today most of the popular programming languages support objects, limiting scope, modularity, passing by value, and sophisticated built-in types. There should be no reason to deliberately expose an object's data to the rest of the code because the language can enforce encapsulation and data hiding.
</blockquote>
<p>
While not specific to PHP, <a href="http://typicalprogrammer.com/?p=23">the post</a> does recommend against them because of one simple reason common to all languages that make them possible - they "break the encapsulation OOP offers". For them, they're like a cheat to get around bad coding practices and are not needed to make a successful application work.
</p>]]></description>
      <pubDate>Mon, 16 Jun 2008 11:19:17 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Tobias Schlitt's Blog: Virtual Properties]]></title>
      <guid>http://www.phpdeveloper.org/news/7813</guid>
      <link>http://www.phpdeveloper.org/news/7813</link>
      <description><![CDATA[<p>
In response to <a href="http://www.phpdeveloper.org/news/7812">this previous post</a> from <i>Jeff Moore</i>, <i>Tobias Schlitt</i> <a href="http://schlitt.info/applications/blog/index.php?/archives/547-Virtual-properties.html">shares some of his own comments</a> on the subject - mainly that he wholeheartedly agrees.
</p>
<blockquote>
The usage of interceptors (<a href="http://de.php.net/manual/en/language.oop5.overloading.php">__get()/__set()/__isset()/__call()</a>) makes your API a lot more readable and comfortable, while maintaining the purpose behind getters and setters: Checking the correctness of values assigned to a property and wrapping around retrieval mechanisms for a property. I personally call the way of maintaining value-correctness for properties through interceptors virtual properties, which fits quite nice I think.
</blockquote>
<p>
<i>Tobias</i> gives an example of what he means by these "virtual properties" with <a href="http://schlitt.info/applications/blog/index.php?/archives/547-Virtual-properties.html">an illustration</a> from something widely used on the <a href="http://ez.no/ezcomponents">eZ Components</a> libraries - comparing one method of setting text to an object to another (just setting versus the wrappers).
</p>]]></description>
      <pubDate>Thu, 10 May 2007 07:57:00 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jeff Moore's Blog: Let Your Properties be Properties]]></title>
      <guid>http://www.phpdeveloper.org/news/7812</guid>
      <link>http://www.phpdeveloper.org/news/7812</link>
      <description><![CDATA[<p>
In a <a href="http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/">recent post</a> to his blog, <i>Jeff Moore</i> advocates the philosophy that, in your OOP application development, you should "let your properties be properties".
</p>
<blockquote>
<p>Some times there are some ancillary methods to deal with unsetting, checking for existence, setting via an array, or dealing with references in PHP 4. They can really clutter up the definition of a class. That's not good.
</p>
<p>
[...] I think the idea is to make the class extensible. But PHP is really ok with just setting new properties on a class. So why not just do this?
</p>
</blockquote>
<p>
He <a href="http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/">argues</a> that getters and setters in a class are less useful than just setting the property yourself. Using the property name as part of the interface, though (like getting the $obj->foo value with $obj->getFoo) is stil clean enough to be useful.
</p>]]></description>
      <pubDate>Thu, 10 May 2007 07:11:45 -0500</pubDate>
    </item>
  </channel>
</rss>
