<?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, 23 May 2013 13:12:43 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[James Fuller's Blog: Enforcing contracts in your PHP functions and methods]]></title>
      <guid>http://www.phpdeveloper.org/news/17720</guid>
      <link>http://www.phpdeveloper.org/news/17720</link>
      <description><![CDATA[<p>
<i>James Fuller</i> has a new post to his blog today about a way you can <a href="http://www.jblotus.com/2012/03/22/enforcing-contracts-in-your-php-functions-and-methods/">enforce contracts in your PHP</a> using a combination of type hinting and value checking.
</p>
<blockquote>
<a href="http://en.wikipedia.org/wiki/Design_by_contract">Design by contract</a> is an important concept for controlling what type of input your methods or functions can receive. One of the most dangerous features of PHP is that functions will still execute even when they are missing required arguments, by emitting a warning instead of an error. In this post, I am going to walk through some of the solutions available to deal with this problem.
</blockquote>
<p>
He shows how to alter a basic function to first use type hinting to catch when a variable is the wrong type (in this case checking for an array and stdClass) which causes a Fatal error and makes the function not execute. He includes sample code for the type/value checking option and also includes a suggestion of using PHPUnit's assertions as another option. 
</p>
<p>
Finally, he introduces the <a href="https://github.com/stuartherbert/ContractLib">ContractLib</a> tool (from <i>Stuart Herbert</i>) that makes use of closures to enforce checks - his example checks to see if something is a string and that it's not empty.
</p>]]></description>
      <pubDate>Fri, 23 Mar 2012 08:37:11 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Stuart Herbert's Blog: ContractLib - An Introduction & Comparing it to PHP's Assert]]></title>
      <guid>http://www.phpdeveloper.org/news/17405</guid>
      <link>http://www.phpdeveloper.org/news/17405</link>
      <description><![CDATA[<p>
<i>Stuart Herbert</i> has two new posts to his blog showing how to use the <a href="https://github.com/stuartherbert/ContractLib">ContractLib</a> tool he's created to define programming "contracts". In <a href="http://blog.stuartherbert.com/php/2012/01/16/getting-started-with-contractlib/">the first</a> he shows some sample usage of the tool and in <a href="http://blog.stuartherbert.com/php/2012/01/17/comparing-contractlib-to-phps-built-in-assert/">the second</a> he compares the functionality of ContractLib's features and PHP's own "<a href="http://us3.php.net/assert">assert</a>" method.
</p>
<blockquote>
<a href="https://github.com/stuartherbert/ContractLib">ContractLib</a> is a simple-to-use PHP component for easily enforcing programming contracts throughout your PHP components. These programming contracts can go a long way to helping you, and the users of your components, develop more robust code.
</blockquote>
<p>
In <a href="http://blog.stuartherbert.com/php/2012/01/16/getting-started-with-contractlib/">his example tests</a> he shows how to set a pre-condition on a method's input ensuring that it will always be the correct datatype (array). In <a href="http://blog.stuartherbert.com/php/2012/01/17/comparing-contractlib-to-phps-built-in-assert/">his comparison</a> with PHP's "assert", he lists out some of the features that either one has and notes that ContractLib allows you to be much more flexible with your checking than just simple statements.
</p>]]></description>
      <pubDate>Tue, 17 Jan 2012 10:58:38 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Stuart Herbert's Blog: Introducing ContractLib (Programming Contracts)]]></title>
      <guid>http://www.phpdeveloper.org/news/17394</guid>
      <link>http://www.phpdeveloper.org/news/17394</link>
      <description><![CDATA[<p>
In <a href="http://blog.stuartherbert.com/php/2012/01/11/introducing-contractlib/">this recent post</a> to his blog <i>Stuart Herbert</i> introduces a system he's created to handle "contracts" in PHP development - <a href="https://github.com/stuartherbert/ContractLib">ContractLib</a>.
</p>
<blockquote>
Programming contracts are tests around functions and methods, and they are normally used: to catch any 'bad' data that has been passed into the function or method from the caller, and to catch any 'bad' data generated by the function or method before it can be returned to the caller. These are pre-condition and post-condition tests, and they are tests that either pass or fail.
</blockquote>
<p>
He points out that by having contracts you not only increase the robustness of your code but you also save time not trying to hunt down data-related issues. Using pre-conditions, you can can check data to ensure things like correct formatting, data that's out of range and data that might be missing. His <a href="https://github.com/stuartherbert/ContractLib">ContractLib</a> comes with a set of <a href="https://github.com/stuartherbert/ContractLib/tree/master/src/tests">tests</a> that provide good examples of how to use the functionality. Installation instructions are included.
</p>]]></description>
      <pubDate>Fri, 13 Jan 2012 14:11:52 -0600</pubDate>
    </item>
  </channel>
</rss>
