<?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, 22 May 2013 13:31:06 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Chris Hartjes: Testing Smells - Try/catch]]></title>
      <guid>http://www.phpdeveloper.org/news/19531</guid>
      <link>http://www.phpdeveloper.org/news/19531</link>
      <description><![CDATA[<p>
In <a href="http://www.littlehart.net/atthekeyboard/2013/04/30/testing-smells-try-catch/">this new post</a> to his site <i>Chris Hartjes</i> gives an example of what he calls a "testing smell". This particular illustration deals with the poor handling of testing and exceptions with try/catch blocks.
</p>
<blockquote>
As part of a project to migrate the PHP code at work from PHP 5.2 to PHP 5.4, I'm using our extensive test suite to look for instances where something that changed between the versions of PHP that we are using has caused some unexpected behaviour. In one of our code bases, I found some tests that are exhibiting a test smell through their use of a try / catch block in the test itself.
</blockquote>
<p>
He includes a (contrived) example showing the use of an exception in a unit test to run an assertion in the "catch" for the test to pass. He points out that this particular check is being done to see if the user input is valid...and that it's a bad way to enforce it using exceptions. He also suggests that if you have an "if" situation, don't use one test with logic in it, write two tests. He mentions a <a href="http://www.brianfenton.us/2011/09/bad-practice-setting-expected.html">disenting opinion</a> but notes that a failing test is a failing test, regardless of what caused the failure.
</p>
Link: http://www.littlehart.net/atthekeyboard/2013/04/30/testing-smells-try-catch]]></description>
      <pubDate>Wed, 01 May 2013 11:42:29 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Rob Allen: Simple logging of ZF2 exceptions]]></title>
      <guid>http://www.phpdeveloper.org/news/19507</guid>
      <link>http://www.phpdeveloper.org/news/19507</link>
      <description><![CDATA[<p>
In <a href="http://akrabat.com/zend-framework-2/simple-logging-of-zf2-exceptions/">this new post to his site</a> <i>Rob Allen</i> shows you how to implement a simple logging method for catching exceptions in your Zend Framework 2 application.
</p>
<blockquote>
I recently had a problem with a ZF2 based website where users were reporting seeing the error page displayed, but I couldn't reproduce in testing. To find this problem I decided to log every exception to a file so I could then go back and work out what was happening. In a standard ZF2 application, the easiest way to do this is to add a listener to the 'dispatch.error' event and log using ZendLog.
</blockquote>
<p>
He uses an event listener to attach a service that contains a "logException" method. This method uses the ZendLog component to write out the error message to a local log file including a backtrace of where the issue occurred.
</p>
Link: http://akrabat.com/zend-framework-2/simple-logging-of-zf2-exceptions]]></description>
      <pubDate>Thu, 25 Apr 2013 10:31:40 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[NetTuts.com: Taming Slim 2.0]]></title>
      <guid>http://www.phpdeveloper.org/news/19396</guid>
      <link>http://www.phpdeveloper.org/news/19396</link>
      <description><![CDATA[<p>
On NetTuts.com today there's a new tutorial posted about <a href="http://net.tutsplus.com/tutorials/php/taming-slim-2-0/">"taming" Slim 2.0</a>, the latest version of the popular PHP microframework. They look at application structure and share some tips to using this update.
</p>
<blockquote>
<a href="http://www.slimframework.com/">Slim</a> is a lightweight framework that packs a lot of punch for its tiny footprint. It has an incredible routing system, and offers a solid base to work from without getting in your way. Let me show you! But that's not to say that Slim doesn't has some issues; it's one-file setup becomes cluttered as your application grows. In this article, we'll review how to structure a Slim application to not only sustain, but improve its functionality and keep things neat and systematic.
</blockquote>
<p>
He starts with an example of "vanilla Slim" and looks some at what's happening behind the scenes in the routing engine. They then give you a step by step installation and usage guide including updating the router to use class files. An example controller is included as well as some basic error handling using a Twig template for use across the application.
</p>]]></description>
      <pubDate>Tue, 02 Apr 2013 09:17:11 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DZone.com: External processes and PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19182</guid>
      <link>http://www.phpdeveloper.org/news/19182</link>
      <description><![CDATA[<p>
In a new tutorial over on DZone.com <i>Giorgio Sironi</i> talks about <a href="http://css.dzone.com/articles/external-processes-and-php">handling external processes</a> in PHP and how to work with <a href="http://php.net/streams">streams</a>.
</p>
<blockquote>
I've come to known a bit about spawning and monitoring new processes from PHP code, while working at Onebip and trying to contribute to Paratest. Here's what you need to know if you think exec() or executing everything in a single .php script is always enough.
</blockquote>
<p>
He starts with a look at the differences between using things like <a href="http://php.net/exec">exec</a> and streams for handling the spawning of other processes. He shows how you have more control when you go with the streams option and process handling with the "proc_*" methods. He also touches on some other things to think about like stream blocking, sleeping and dealing with multiple execution streams (and switching between them).
</p>]]></description>
      <pubDate>Thu, 14 Feb 2013 11:29:04 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Matthew Weier O'Phinney: RESTful APIs with ZF2, Part 2]]></title>
      <guid>http://www.phpdeveloper.org/news/19180</guid>
      <link>http://www.phpdeveloper.org/news/19180</link>
      <description><![CDATA[<p>
<i>Matthew Weier O'Phinney</i> has posted the <a href="http://www.mwop.net/blog/2013-02-13-restful-apis-with-zf2-part-2.html">second part of his series</a> looking at creating RESTful APIs with the Zend Framework v2. In the <a href="http://phpdeveloper.org/news/19170">previous post</a> he covered some of the basics of data and structure. In this new article he looks at content types, status codes and two ways to represent them back to your users.
</p>
<blockquote>
In my <a href="http://www.mwop.net/blog/2013-02-11-restful-apis-with-zf2-part-1.html">last post</a>, I covered some background on REST and the Richardson Maturity Model, and some emerging standards around hypermedia APIs in JSON; in particular, I outlined aspects of Hypermedia Application Language (HAL), and how it can be used to define a generic structure for JSON resources. In this post, I cover an aspect of RESTful APIs that's often overlooked: reporting problems.
</blockquote>
<p>
He starts with some of the things around error handling and APIs that bother him and why just returning a status code representing an error isn't enough. He suggests two possible solutions to this issue - two messaging formats, API-Problem and vnd.error. He gives brief summaries of each and includes example output to give them some context.
</p>]]></description>
      <pubDate>Thu, 14 Feb 2013 09:15:06 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Joshua Thijssen: PHP5.5: Try/Catch/Finally]]></title>
      <guid>http://www.phpdeveloper.org/news/19169</guid>
      <link>http://www.phpdeveloper.org/news/19169</link>
      <description><![CDATA[<p>
<i>Joshua Thjissen</i> has a new post to his site today about a feature that's been introduced in the upcoming PHP 5.5 release of the language - the addition of "finally" to try/catch exception handling. He gets into it <a href="http://www.adayinthelifeof.nl/2013/02/12/php5-5-trycatchfinally/">a bit more technically</a> than just the "introductory" level, discussing parent/child exception handling and using returns.
</p>
<blockquote>
Exception handling is available in PHP since version 5.  It allows you to have a more fine-grained control over code when things go wrong ie, when exceptions occur. But since PHP 5.5, exception handling has finally evolved into what it should have been from the beginning: the "finally" part has been implemented.
</blockquote>
<p>
He includes a basic example showing how a certain part is always executed, regardless of if the exception is thrown or not. He also shows how a "chained catch" would work to catch multiple kinds of exceptions and when the "finally" is run as it relates to the "trickle down" handling of exceptions. He then gets a little more complex and introduces "return" into the mix. Of special note, even if you return, the "finally" will still get called.
</p>]]></description>
      <pubDate>Tue, 12 Feb 2013 10:03:23 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Lorna Mitchell: How NOT to Design Your API]]></title>
      <guid>http://www.phpdeveloper.org/news/19019</guid>
      <link>http://www.phpdeveloper.org/news/19019</link>
      <description><![CDATA[<p>
Recently <i>Lorna Mitchell</i> asked the wide world of Twitter about some of their recommendations of things <b>not</b> to do when creating an API. In <a href="http://www.lornajane.net/posts/2013/how-not-to-design-your-api">this new post</a> to her site, she gathers together those responses including comments about documentation, consistency and response codes.
</p>
<blockquote>
Recently I tweeted as a <a href="http://linktuesday.com/">#linktuesday</a> link the <a href="http://blog.programmableweb.com/2012/08/03/top-10-api-worst-practices/">10 Worst API Practices post from ProgrammableWeb</a>. Today, in search of some concrete examples of APIs implementing unhelpful antipatterns, I sent out a tweet for help: "What's the most frustrating inconsistent/misleading bit of API you've seen? Looking for cautionary tales!" [...] In the raft of responses (and thankyou all, this was fabulous, helpful and entertaining in equal parts!), there were some definite patterns that I'd like to share with you, in no particular order.
</blockquote>
<p>Comments came in from all over and talked about things like:</p>
<ul>
<li>Response codes not matching the content (ex. 200 on an error)
<li>NullPointerExceptions
<li>Different endpoints for single vs collections
<li>Order-sensitive XML in requests
<li>Poor error handling
<li>Bad documentation
<li>Incorrect content type handling
</ul>
<blockquote>
So there you have it, the sins to avoid in your own APIs. If you've encountered any of these, please accept my condolences.
</blockquote>]]></description>
      <pubDate>Thu, 10 Jan 2013 10:46:04 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Derick Rethans: Connection Handling with the MongoDB PHP driver]]></title>
      <guid>http://www.phpdeveloper.org/news/18839</guid>
      <link>http://www.phpdeveloper.org/news/18839</link>
      <description><![CDATA[<p>
Continuing on with his look at the newly released version of the MongoDB driver for PHP <i>Derick Rethans</i> has <a href="http://derickrethans.nl/mongodb-connection-handling.html">posted more detail</a> about the advanced connection handling options this new driver version provides.
</p>
<blockquote>
The 1.3 release series of the PHP <a href="http://mongodb.org/">MongoDB</a> driver features a rewritten connection handling library. This is quite a large change and changes how the PHP driver deals with persistent connections and connection pooling.
</blockquote>
<p>
He starts with an example of a v1.2 driver connection, how the connection is requested from a pool and how, based on the integration of a worker into the connection process, v1.3 handles the connection requests. He includes a bit about replica set connections and authentication connections, complete with PHP code examples showing them in practice.
</p>]]></description>
      <pubDate>Tue, 04 Dec 2012 10:54:15 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso: Handling dates with PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/18540</guid>
      <link>http://www.phpdeveloper.org/news/18540</link>
      <description><![CDATA[<p>
In <a href="http://gonzalo123.com/2012/10/01/handling-dates-with-php/">this new post</a> to his site <i>Gonzalo Ayuso</i> introduces you to one of the more powerful parts of the PHP language - the <a href="http://php.net/datetime">DateTime</a> object.
</p>
<blockquote>
I've seen a lot of newbies (and not newbies) having problems handling dates in PHP (and even with SQL and another languages). When I see someone having problems with dates, I always ask the same question. I type in a text editor "27/11/2012&#8243; and I ask him: What is it? If your answer is "This is a date" you should continue reading the post.
</blockquote>
<p>
He talks about how the DateTime functionality replaces (much more effectively) some of the older date handling methods in PHP. He includes a few examples comparing it to <a href="http://php.net/date">date</a> and showing how it can be used to compare dates. He includes a "Dummy" class he mocked up to show how you could work with DateTime to get/set formatted dates, set the format to use and get the current format. As always, he also provides tests for the code as well.
</p>
<p>
This is just the tip of the iceberg as to what DateTime can do, so I'd suggest checking out <a href="http://php.net/manual/book.datetime.php">the manual page</a> for it to see the full list of features.
</p>]]></description>
      <pubDate>Tue, 02 Oct 2012 08:41:09 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Patterns for Flexible View Handling, Part 2 - Using Decorators]]></title>
      <guid>http://www.phpdeveloper.org/news/18448</guid>
      <link>http://www.phpdeveloper.org/news/18448</link>
      <description><![CDATA[<p>
PHPMaster.com has posted the second part in their series looking at design patterns in handling views in your framework of choice. In <a href="http://phpmaster.com/flexible-view-manipulation-2/">this new article</a> they focus on the decorator pattern, using additional functionality to augment the results from the view being rendered.
</p>
<blockquote>
It's also feasible to manipulate views in fairly flexible fashion by appealing to the niceties of a few other patterns as well, including the rather underrated <a href="http://en.wikipedia.org/wiki/Decorator_pattern">Decorators</a>. If you're wondering in what parallel universe Decorators get along with views, in this part I'll be showing how to put them to work side by side in nice orchestration to bring to life yet another view module.
</blockquote>
<p>
They create a simple example where an HTML element (based on an interface) is rendered - a span tag - with content passed in on creation. They take this same logic and transfer it over to the View handler, making handlers for difference pieces of the content (outer and inner). These decorators are then passed in the data from the view and rendered in order.
</p>]]></description>
      <pubDate>Wed, 05 Sep 2012 11:18:58 -0500</pubDate>
    </item>
  </channel>
</rss>
