<?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>Sat, 25 May 2013 02:03:31 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Brandon Savage: Always Return Something]]></title>
      <guid>http://www.phpdeveloper.org/news/19301</guid>
      <link>http://www.phpdeveloper.org/news/19301</link>
      <description><![CDATA[<p>
In <a href="http://www.brandonsavage.net/always-return-something">this post</a> to his site <i>Brandon Savage</i> talks about "always returning something" from your methods and functions back to the calling script. He also suggests that null is not an option.
</p>
<blockquote>
A few weeks ago, there was a discussion on Twitter about whether or not a method should always return a value, or whether or not null was a valid value to return. The answer to this question is a resounding no, a null value should never be returned. [...] For example, you check that a file you opened exists, or that a resource performed correctly before using it. But if you receive a null response, how do you test for this The answer is you can't
</blockquote>
<p>
He notes that a "null" response is not only difficult to test but can lead to ambiguous handling as you're not sure where the error might be. He also includes a snippet of code showing how a null response could break a fluent interface if an instance of "$this" is not returned.
</p>]]></description>
      <pubDate>Tue, 12 Mar 2013 10:49:55 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Michael Nitschinger: A Journey on Avoiding Nulls in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19210</guid>
      <link>http://www.phpdeveloper.org/news/19210</link>
      <description><![CDATA[<p>
<i>Michael Nitschinger</i> has written up a post looking at <a href="http://nitschinger.at/A-Journey-on-Avoiding-Nulls-in-PHP">avoiding nulls in your applications</a> in favor of a better kind of value handling - the introduction of "<a href="http://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained">Optional</a>" handling.
</p>
<blockquote>
While every developer has kind of accepted their existence, they are suddenly there when we'd desperately need them to not show up. How often did you writeif($obj === null) in your PHP code? Can't there be a better, more elegant and fault-tolerant solution to the problem?
</blockquote>
<p>
His solution is to create a PHP version of this "Optional" functionality (via an abstract class) that allows some evaluation of the returned value from method calls on the object. Methods like "isPresent", "getOrElse", "of" and "fromNullable"  make it easier to work with null values instead of just the triple-equals checking. He includes not only the code for the classes you'll need to implement it but examples of it in use - an "Optional" abstract class and two child classes, "Present" and "Absent".
</p>]]></description>
      <pubDate>Wed, 20 Feb 2013 12:17:39 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Stoimen Popov's Blog: PHP: Don't Call the Destructor Explicitly]]></title>
      <guid>http://www.phpdeveloper.org/news/17136</guid>
      <link>http://www.phpdeveloper.org/news/17136</link>
      <description><![CDATA[<p>
In <a href="http://www.stoimen.com/blog/2011/11/14/php-dont-call-the-destructor-explicitly/">this new post</a> to his blog <i>Stoimen Popov</i> talks about calling the "destructor" method of an object and why doing it directly could lead to some issues - like not actually destroying the object before the script ends.
</p>
<blockquote>
At the end of the script the interpreter frees the memory. Actually every object has a built-in destructor, just like it has built-in constructor. So even we don't define it explicitly, the object has its destructor. Usually this destructor is executed at the end of the script, or whenever the object isn't needed anymore. This can happen, for instance, at the end of a function body. Now if we call the destructor explicitly, which as I said I've seen many times, here's what happen. As you can see calling the destructor explicitly doesn't destroy the object. So the question is...how to destroy an object before the script stops?
</blockquote>
<p>
He points out that one way to "destroy" an object is to null it out and remove the structure from memory. This is tricky, though, because a clone of the object will still exist in memory, just not the original.
</p>]]></description>
      <pubDate>Wed, 16 Nov 2011 11:56:43 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Dan Horrigan's Blog: The Value of Null]]></title>
      <guid>http://www.phpdeveloper.org/news/16217</guid>
      <link>http://www.phpdeveloper.org/news/16217</link>
      <description><![CDATA[<p>
<i>Dan Horrigan</i> has a new post to his blog talking about <a href="http://coderepeat.com/post/4624154050/the-value-of-null">the value of null</a> - a quick summary about when and where null should be used. Null's a value too, after all...
</p>
<blockquote>
Let me start off by saying this article is about PHP and PHP alone.  Other languages handle this sort of thing differently (and better). In PHP many people (and a few frameworks) return FALSE from methods when the requested value does not exist.  However, I am here to tell you that if you do this, you are doing it wrong.  Plain and Simple.
</blockquote>
<p>
In his opinion, "false" is definitely not the same thing as "null" because "null" is technically the absence of a value, not a "not true" value like "false" is. He illustrates with a simple use case of a class that has methods returning various values. 
</p>]]></description>
      <pubDate>Tue, 19 Apr 2011 10:51:18 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jani Hartikainen's Blog: What is a null object, and when are they useful?]]></title>
      <guid>http://www.phpdeveloper.org/news/13219</guid>
      <link>http://www.phpdeveloper.org/news/13219</link>
      <description><![CDATA[<p>
In <a href="http://codeutopia.net/blog/2009/09/12/what-is-a-null-object-and-when-are-they-useful/">this latest post</a> to his blog <i>Jani Hartikainen</i> looks at creating "null objects" for your applications - a simple tool that lets you replace multiple evaluation checks with a simple object.
</p>
<blockquote>
How many times have you written code, which checks if a value is null, and then displays something special because of that? Have you written the very same check in more than one place in your code? A null object is an elegant solution to this. 
</blockquote>
<p>
His example shows how to replace a standard User class to grab the user's name with an anonymous user that extends it to return the string "Anonymous User" instead. By creating an intermediate class like this, you can simple call a "getName" and know that there will be some sort of value as the result.
</p>]]></description>
      <pubDate>Mon, 14 Sep 2009 12:46:10 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Davey Shafik's Blog: Return Values]]></title>
      <guid>http://www.phpdeveloper.org/news/11879</guid>
      <link>http://www.phpdeveloper.org/news/11879</link>
      <description><![CDATA[<p>
<i>Davey Shafik</i> has <a href="http://pixelated-dreams.com/archives/479-return-values.html">taken a look at return values</a> and keeping them standard when handing them back from the results of a database query.
</p>
<blockquote>
In #phpc we recently had a discussion about function return values; specifically from database queries. I'm going to go on a (admittedly, rather sturdy looking) limb and say this applies to pretty much any function that returns from a data resource, not just a database .
</blockquote>
<p>
His personal preference is to return the results data if there's matching information but to return a false value if there is an error/not results were found. He includes a snippet of example code to show the structure he's talking about. Some of <a href="http://pixelated-dreams.com/archives/479-return-values.html#comments">the comments</a> on the post mention things like exception handling, other similar methods other developers use and the use of nulls.
</p>]]></description>
      <pubDate>Wed, 04 Feb 2009 11:14:28 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Brian Moon's Blog: Null vs. isset()]]></title>
      <guid>http://www.phpdeveloper.org/news/11837</guid>
      <link>http://www.phpdeveloper.org/news/11837</link>
      <description><![CDATA[<p>
In <a href="http://brian.moonspot.net/null-isset-php">this new post</a> to his blog, <i>Brian Moon</i> compares two things that, on the outside, might seem a lot alike but do have their differences under the hood - a null value and the <a href="http://php.net/isset">isset</a> function.
</p>
<blockquote>
I am working with a newcomer to PHP and he asked me about setting a variable to null and how to check that.  He had found some example or information that showed that setting a varaible equal to null would unset the variable. So, he was unclear if he could then reliably check if the variable was equal to null.  Having avoided null like the plague in my years of PHP, I was not sure. So, I mocked up a quick script to see what the states of a variable are in relation to null.
</blockquote>
<p>
His test verified that a variable, set equal to null will be found to be equal to null, will be set (<a href="http://php.net/isset">isset</a>) and will be found empty by PHP's <a href="http://php.net/empty">empty</a>
</p>]]></description>
      <pubDate>Thu, 29 Jan 2009 09:34:59 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Null and Empty Strings]]></title>
      <guid>http://www.phpdeveloper.org/news/11496</guid>
      <link>http://www.phpdeveloper.org/news/11496</link>
      <description><![CDATA[<p>
On DevShed today, there's a <a href="http://www.devshed.com/c/a/MySQL/Null-and-Empty-Strings/">new tutorial</a> posted looking at two things that can cause headaches for PHP developers (especially when evaluating and comparing values) - nulls and empty strings.
</p>
<blockquote>
Anyone who has programmed for any length of time has encountered the concepts of null and empty strings. They are not the same, and confusing the two can cause some serious problems. This article deals with these concepts in the context of PHP and MySQL.
</blockquote>
<p>
They start with a bit of a quiz before getting into how to handle them correctly - making null "safe" and working with it correctly in a MySQL context. SQL statements and table structures are included for their examples.
</p>]]></description>
      <pubDate>Wed, 03 Dec 2008 11:16:51 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Clay Loveless' Blog: PHP and JSON: Cut #987]]></title>
      <guid>http://www.phpdeveloper.org/news/7364</guid>
      <link>http://www.phpdeveloper.org/news/7364</link>
      <description><![CDATA[<p>
In a <a href="http://killersoft.com/randomstrings/2007/02/28/php-and-json-cut-987/">new post</a> today, <i>Clay Loveless</i> talks about some issues he's been having with PHP and JSON, specifically with the JSON encoding method in PHP 5.2.1.
</p>
<blockquote>
As of PHP 5.2.1, json_decode() no longer follows <a href="http://www.ietf.org/rfc/rfc4627.txt">the published standards</a> for JSON-encoded texts. Why not? For no reason other than the convenience of those ignorant of JSON standards.
</blockquote>
<p>
His complaint stems from the results of a vat_dump statement - prior to this version it would give a NULL, but now it returns a "bool(true)" value back, resulting in some breakage of previous scripts. He spends the rest of the post explaining his voyage through the JSON world and how things are supposed to behave. He also digs a little deeper into the var_dump issue and why he thinks it's such a bad thing.
</p>]]></description>
      <pubDate>Thu, 01 Mar 2007 08:43:00 -0600</pubDate>
    </item>
  </channel>
</rss>
