<?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>Thu, 24 May 2012 10:32:24 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Rob Allen's Blog: Returning JSON using the Accept header in ZF2]]></title>
      <guid>http://www.phpdeveloper.org/news/17756</guid>
      <link>http://www.phpdeveloper.org/news/17756</link>
      <description><![CDATA[<p>
In a <a href="http://phpdeveloper.org/news/17748">previous post</a> <i>Rob Allen</i> showed how to return JSON data from a controller in a Zend Framework 2 application. In <a href="http://akrabat.com/zend-framework-2/returning-json-using-the-accept-header-in-zf2/">this new post</a> he shows how to use the "Accepts" header from the client to do the same thing.
</p>
<blockquote>
Following yesterday's article on <a href="http://akrabat.com/zend-framework-2/returning-json-from-a-zf2-controller-action/">returning JSON from a ZF2 controller action</a>, <a href="http://twitter.com/lsmith">Lukas</a> suggested that I should also demonstrate how to use the Accept header to get JSON. So this is how you do it!
</blockquote>
<p>
You'll need to <a href="http://akrabat.com/zend-framework-2/returning-json-from-a-zf2-controller-action/">create the JsonStrategy</a> first, then you can return the ViewModel from the controller. If all goes well, you should see the sample HTML page rendered in a browser and JSON output when requested with the right "Accept" header (he uses curl in his example).
</p>]]></description>
      <pubDate>Fri, 30 Mar 2012 08:01:56 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Rob Allen's Blog: Returning JSON from a ZF2 controller action]]></title>
      <guid>http://www.phpdeveloper.org/news/17748</guid>
      <link>http://www.phpdeveloper.org/news/17748</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Rob Allen</i> shows how you can return JSON data <a href="http://akrabat.com/zend-framework-2/returning-json-from-a-zf2-controller-action/">directly back from a controller</a> in a Zend Framework 2 application.
</p>
<blockquote>
The new view layer in Zend Framework 2 can be set up to return JSON rather than rendered HTML relatively easily. [...] Firstly we need to set up the view's JsonStrategy to check to a situation when returning JSON is required and then to render out JSON for us.
</blockquote>
<p>
This "JsonStrategy" does some of the hard work for you - detecting when the client is requesting a JSON response and looking at the data coming into the view to see if it's JSON. He shows how to implement it in a sample module using the "onBootstrap" module and how to force a return of the JsonModel even when JSON isn't requested (useful for a consistent interface).
</p>]]></description>
      <pubDate>Thu, 29 Mar 2012 08:55:39 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Timothy Boronczyk's Blog: Avoid Fetch-Object Abuse]]></title>
      <guid>http://www.phpdeveloper.org/news/16581</guid>
      <link>http://www.phpdeveloper.org/news/16581</link>
      <description><![CDATA[<p>
In a new post on his blog <i>Timothy Boronczyk</i> has a recommendation for developers working in PHP with databases that have a "fetch object" method - <a href="http://zaemis.blogspot.com/2011/07/avoid-fetch-object-abuse.html">use it correctly or avoid it all together</a>.
</p>
<blockquote>
Lately I'm finding a lot of instances of the mysql_fetch_object() function being used in a particular codebase I help maintain. Unfortunately, I've yet to see it used correctly. It always seems to be used to retrieve a stdClass object from a query result where mysql_fetch_array() or mysql_fetch_assoc() would be the more appropriate choice.
</blockquote>
<p>
Most of his complaint is that, despite pulling out the data as an object, most scripts continue to use it like you would an array, looping over it. There's extra overhead generated from the object creation that could cause issues, especially with large return data sets.
</p>
<blockquote>
The best advice I can offer is to educate yourself and others how the function should be used so its abuse isn't perpetuated. Then, be cautious when using mysql_fetch_object() correctly and understand the process it follows to create and return an object. If not for yourself, then do it for the kittens.
</blockquote>]]></description>
      <pubDate>Tue, 12 Jul 2011 12:10:02 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Lorna Mitchell's Blog: PHP Returning Numeric Values in JSON]]></title>
      <guid>http://www.phpdeveloper.org/news/16577</guid>
      <link>http://www.phpdeveloper.org/news/16577</link>
      <description><![CDATA[<p>
<i>Lorna Mitchell</i> has a <a href="http://www.lornajane.net/posts/2011/PHP-Returning-Numeric-Values-in-JSON">quick reminder</a> about an issue in the new <a href="http://joind.in/">joind.in</a> API version - everything was being returned as strings, even integers.
</p>
<blockquote>
A few weeks later (my inbox is a black hole and it takes a while to process these things) I fell over a throwaway comment to an undocumented constant JSON_NUMERIC_CHECK, and I added the constant name to my todo list. In the time it took for me to actually get around to googling for this, some wonderful person updated the PHP manual page (this is why I love PHP) to include it as a documented option, and someone else had added a user contributed note about using it.
</blockquote>
<p>
This option, JSON_NUMERIC_CHECK, tells the <a href="http://php.net/json_encode">json_encode</a> function to property consider numbers in its encoding process. It applies globally, so if there's an instance where you don't want something assigned as a number, you might need to go with another, more flexible JSON encoding option. You can find information about this and other possible options json_encode can take on <a href="http://us.php.net/json_encode">its manual page</a>.
</p>
]]></description>
      <pubDate>Tue, 12 Jul 2011 08:41:39 -0500</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[Brian Swan's Blog: SQL Server Driver for PHP Connection Options: ReturnDatesAsStrings]]></title>
      <guid>http://www.phpdeveloper.org/news/15876</guid>
      <link>http://www.phpdeveloper.org/news/15876</link>
      <description><![CDATA[<p>
<i>Brian Swan</i> has a new post to his blog today looking at one of the <a href="http://blogs.msdn.com/b/brian_swan/archive/2011/02/08/sql-server-driver-for-php-connection-options-returndatesasstrings.aspx">connection options for the SQL Server driver</a> in PHP - the "ReturnDatesAsStrings" setting that can make handling date and time information simpler for PHP.
</p>
<blockquote>
This is short post to address a frustration I've seen mentioned on Twitter and in forums a lot: By default, the SQL Server Driver for PHP returns <a href="http://msdn.microsoft.com/en-us/library/ms187819.aspx">datetime</a> columns as <a href="http://www.php.net/manual/en/class.datetime.php">PHP DateTime</a> objects, not strings. This can be especially frustrating if you are not aware of the ReturnDatesAsStrings connection option. By simply setting this option to 1 (or true) when you connect to the server, datetime columns will be returned as strings.
</blockquote>
<p>
He includes some sample code showing how to use the setting (as a part of the settings array passed in to sqlsrv_connect) and the resulting array key from the fetched results on his sample table. This just gives you one more option for handling dates in your SQL Server-based application, especially if you don't need the full DateTIme object's functionality.
</p>]]></description>
      <pubDate>Wed, 09 Feb 2011 08:45:28 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Jani Hartikainen's Blog: Should a failed function return a value or throw an exception?]]></title>
      <guid>http://www.phpdeveloper.org/news/14173</guid>
      <link>http://www.phpdeveloper.org/news/14173</link>
      <description><![CDATA[<p>
<i>Jani Hartikainen</i> poses an interesting question on his blog today - is it more correct for a function, having failed at its job, to <a href="http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/">return a value of throw an exception</a>.
</p>
<blockquote>
You have created a nice, well written function, but you realize you forgot something: The failure case. What should a function do when it fails? There are two schools for this - the "throw an exception" school and the "return an error value" school. But which of these is the correct approach?
</blockquote>
<p>
He suggests that this debate has stuck around from the time when there weren't exceptions in several popular programming languages and that returning the value was the only valid way. He touches on what an exception condition is (with a few code examples) and situations where each choice might be the right way to go. 
</p>]]></description>
      <pubDate>Fri, 12 Mar 2010 10:41:43 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Community News: php|architect Podcast Returns!]]></title>
      <guid>http://www.phpdeveloper.org/news/13108</guid>
      <link>http://www.phpdeveloper.org/news/13108</link>
      <description><![CDATA[<p>
<a href="http://phparch.com">php|architect</a> has resurrected their podcast after quite a while to bring you the latest "news, opinion and pure, unadulterated PHP gossip" for your listening pleasure.
</p>
<blockquote>
We're proud to announce that our ever-so-popular podcast is <a href="http://phparch.com/podcast">back on the air</a> after a long hiatus'"in fact, we've got a brand-new format,  a brand-new theme song...and even a brand new voice guy (but we could only afford him for the intro, so you're stuck with Marco's hypernasal voice and Super Mario-like accent for the rest of the show).
</blockquote>
<p>
In <a href="http://phparch.com/podcast/get/20090824">this new episode</a> <i>Marco</i>, <i>Beth</i>, <i>Keith</i> and <i>Davey</i> talk about the "PHP vs. ASP" debate, SXSW, PHP 5.3 and what's coming up in the latest php|architect issue. You can <a href="http://phparch.com/podcast/get/20090824">download the mp3</a> or <a href="http://phparch.com/podcast/feed">add the feed</a> to your reader to get the latest episodes as soon as they're released.
</p>]]></description>
      <pubDate>Tue, 25 Aug 2009 14:32:50 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Returning Strings from Views with Code Igniter ]]></title>
      <guid>http://www.phpdeveloper.org/news/12317</guid>
      <link>http://www.phpdeveloper.org/news/12317</link>
      <description><![CDATA[<p>
DevShed has posted the next in their "Introduction to CodeIgniter" series - <a href="http://www.devshed.com/c/a/PHP/Returning-Strings-from-Views-with-Code-Igniter/">this new tutorial</a> about returning strings back from the views of your application.
</p>
<blockquote>
Speaking more specifically, it's possible to feed the "$this->load->view()" method of CI a third Boolean parameter, to return the contents of a view to calling code after the view has been parsed. This is a handy variation of the method demonstrated in the previous article, and in this tutorial I'll be taking a close look at it, so you can grasp its underlying logic.
</blockquote>
<p>
<A href="http://www.devshed.com/c/a/PHP/Returning-Strings-from-Views-with-Code-Igniter/2/">This technique</a> could be useful when you want to render a certain block of code but don't want the application to have to reparse and rerender it. Pass the information to one view call, return the output back into a variable and push that back out into a main view any number of times.
</p>]]></description>
      <pubDate>Fri, 10 Apr 2009 08:43:41 -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>
  </channel>
</rss>

