<?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 22:37:21 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[PHPEasy.co.uk: Tutorial: Type Hinting in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/18304</guid>
      <link>http://www.phpdeveloper.org/news/18304</link>
      <description><![CDATA[<p>
On the PHPEasy.co.uk site there's a quick new tutorial posted about <a href="http://phpeasy.co.uk/tutorial-type-hinting-in-php/">type hinting in PHP</a> - how to use it and why you should use it in your code.
</p>
<blockquote>
Type hinting allows you to tell a function which data type to accept for its arguments. When you call a function, if a type hint is present, the argument passed will be checked to make sure it is of the type specified. If a function has control over what it accepts as an argument, then it is more likely that the code within the function will have the data it needs to perform the task it is intended for. 
</blockquote>
<p>
He includes two code examples - one not using a type hinting on the parameters (assuming the correct arguments) and another forcing the input of the "PrintGuitar" method to be a "Guitar" object instance. You can find out more about type hinting in <a href="http://us3.php.net/manual/en/language.oop5.typehinting.php">the PHP manual</a>.
</p>]]></description>
      <pubDate>Wed, 01 Aug 2012 12:14:35 -0500</pubDate>
    </item>
    <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[DZone.com: Reuse your closures with functors]]></title>
      <guid>http://www.phpdeveloper.org/news/15651</guid>
      <link>http://www.phpdeveloper.org/news/15651</link>
      <description><![CDATA[<p>
On DZone.com there's <a href="http://css.dzone.com/articles/reuse-your-closures-functors">a new tutorial</a> from <i>Giorgio Sironi</i> about reusing closures with the help of functors (a special kind of object instancing done in PHP with the help of __invoke).
</p>
<blockquote>
I like PHP closures and their superset, anomyous functions, as they implement the Command pattern very well when used correctly. However I feel that sometimes they are: difficult to reuse and difficult to force contracts on. [...] What if we wanted instead, a closure which we can instance even more than one time (maybe with different variables), and that we could type hint?
</blockquote>
<p>
He shows how to make this possible with a functor created using the __invoke magic method of PHP to handle the request to an object like a function. He includes some sample code to show it in action - a basic callback (SquareCallback) and how it compares to calling a normal closure. It also shows something a bit more technical, an "AdderCallback" class that can be defined as a type hint on a function.
</p>]]></description>
      <pubDate>Wed, 29 Dec 2010 10:50:19 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[OpenSky Blog: Inheritance in PHP, or why you want to use an Interface or an Abstract class...]]></title>
      <guid>http://www.phpdeveloper.org/news/15514</guid>
      <link>http://www.phpdeveloper.org/news/15514</link>
      <description><![CDATA[<p>
On the OpenSky blog today there's <a href="http://engineering.shopopensky.com/post/inheritance-in-php-or-why-you-want-to-use-an-interface-or-an-abstract-class">a new post</a> about object oriented development and class structure. More specifically about how you should use interfaces and abstract classes if you want to truly lock down the methods of your classes.
</p>
<blockquote>
Every class has an interface, every class can be typehinted as a method argument, typehint lets you specify the collaborator requirements. Not every typehint is the same.
</blockquote>
<p>
He includes an example of how, despite a "BankAccount" type hint, classes for different types of accounts can be created and methods from the parent can be overwritten. To help remedy the situation, he shows a more structured example that uses interfaces/an abstract class to define the BankAccount structure, setting requirements on the child class functionality. 
</p>]]></description>
      <pubDate>Tue, 30 Nov 2010 11:09:17 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Ilia Alshaetsky's Blog: Type Hinting - Conclusion]]></title>
      <guid>http://www.phpdeveloper.org/news/12928</guid>
      <link>http://www.phpdeveloper.org/news/12928</link>
      <description><![CDATA[<p>
Following up on all of the craziness that was caused by the suggestion of including type hinting into the PHP core, <i>Ilia Alshaetsky</i> <A href="http://ilia.ws/archives/207-Type-Hinting-Conclusion.html">recently posted</a> some of his thoughts on how things turned out and where he'll go from here.
</p>
<blockquote>
Unfortunately, while initial outpouring of support for inclusion of type hinting into PHP 5.3 and 6 was substantial, it all kinda petered out once more people started voting. To be specific, there is a large amount of support for the feature in general, but very few people seem to think it should go into 5.3. [...] That said, at work we will transition to 5.3 soon, probably around 5.3.2/3 time, so I do need a type hinting patch. To that effect I've cleaned up and improved the old patch based on comments from various people, notably Stas and Dmitry (thank guys) and made a copy that I intend to use for work.
</blockquote>
<p>
He talks about how <a href="http://ilia.ws/patch/type_hint_final.txt">the patch</a> works - no more virtual types and no casting support. Three things have been changed to make it all work: modification to the parser, added a getTypeHint function, properly parse type hints in the code.
</p>]]></description>
      <pubDate>Thu, 23 Jul 2009 08:27:52 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Tibo Beijen's Blog: Explicit PHP6?]]></title>
      <guid>http://www.phpdeveloper.org/news/12676</guid>
      <link>http://www.phpdeveloper.org/news/12676</link>
      <description><![CDATA[<p>
<i>Tibo Beijen</i> takes <A href="http://www.tibobeijen.nl/blog/2009/06/11/explicit-php6/">his own look</a> at some of what PHP6 will have to offer and talks a bit about how it would have helped him in a current project:
</p>
<blockquote>
I'm currently working on [a project] where I've been experimenting with 'domain objects' having 'scalar' or 'value' objects as properties (more on that later).
</blockquote>
<p>
The talks specifically about two of the upcoming features - type hinting and the __cast magic method that allows you to correctly cast a variable into a different type. He illustrates with some code that handles and manipulates user data and handles exceptions on an incorrect type cast.
</p>]]></description>
      <pubDate>Fri, 12 Jun 2009 10:27:26 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Max Horvath's Blog: Type Hints for scalar values - PHPTypeSafe now compatible with current PHP 5.3]]></title>
      <guid>http://www.phpdeveloper.org/news/12570</guid>
      <link>http://www.phpdeveloper.org/news/12570</link>
      <description><![CDATA[<p>
<i>Max Horvath</i> has <a href="http://www.maxhorvath.com/2009/05/type-hints-for-scalar-values-phptypesafe-now-compatible-with-current-php-53.html">released a new version</a> of his <a href="http://wiki.github.com/max-horvath/PHPTypeSafe">PHPTypeSafe</a> (a tool to give you type safety for method calls). Now it's compatible with the upcoming PHP 5.3 release too.
</p>
<blockquote>
It is now compatible with the current version of PHP 5.3 (right now it is RC2). I think we won't see any major changes with the namespace handling in PHP 5.3 anymore, so I felt I could upgrade the library. 
</blockquote>
<p>
You can clone the source for the tool from <a href="http://wiki.github.com/max-horvath/PHPTypeSafe">its github page</a> and check out the blog post for an example of it in use.
</p>]]></description>
      <pubDate>Tue, 26 May 2009 11:15:52 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Stubbles Blog: Two New PHP6 Wishlist Items]]></title>
      <guid>http://www.phpdeveloper.org/news/7321</guid>
      <link>http://www.phpdeveloper.org/news/7321</link>
      <description><![CDATA[<p>
Launching off from <a href="http://www.phpdeveloper.org/news/7309">this previous post</a> on the Stubbles Blog, two more posts (from two other developers) have been posted on the same subject:
<ul>
<li>In <a href="http://www.stubbles.org/archives/6-Wishlist-pt1-extended-more-type-hints.html">this new post</a>, <i>Frank Kleine</i> takes things a step further and talks about the same kind of type hinting but for more types - including arrays and objects. Examples of how he'd expect things to work followed.
<li><a href="http://www.stubbles.org/archives/7-My-wishlist-for-PHP-6,-pt2-Namespaces.html">The other post</a> is from <i>Stephan Schmidt</i> again and varies slightly off into the world of Namespaces to be included in PHP6 along with the use of annotations.
</ul>
Be sure to check out the comments <a href="http://www.stubbles.org/archives/6-Wishlist-pt1-extended-more-type-hints.html">on</a> <a href="http://www.stubbles.org/archives/7-My-wishlist-for-PHP-6,-pt2-Namespaces.html">each</a> for some more interesting tidbits...
</p>]]></description>
      <pubDate>Wed, 21 Feb 2007 10:29:00 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Stubbles Blog: My wishlist for PHP 6, pt1: The 'object' type hint]]></title>
      <guid>http://www.phpdeveloper.org/news/7309</guid>
      <link>http://www.phpdeveloper.org/news/7309</link>
      <description><![CDATA[<p>
<i>Stephan Schmidt</i> has <a href="http://www.stubbles.org/archives/5-My-wishlist-for-PHP-6,-pt1-The-object-type-hint.html">posted some thoughts</a> about type hinting in PHP5 (what's there) and the same kind of functionality for objects in PHP6 (what's to come).
</p>
<blockquote>
I was very pleased, that PHP 5 introduced type hints, although they are not available for primitives like string, int, boolean, etc. Still, I'd like to see the object type hint introduced in any future version of PHP that allows me to specify, that a method or function only accepts an object, regardless of the type of the object.
</blockquote>
<p>
He <a href="http://www.stubbles.org/archives/5-My-wishlist-for-PHP-6,-pt1-The-object-type-hint.html">gives the example</a> of Java's handling of the functionality and what PHP does with the same type of code. He also mentions that, via the <a href="http://us2.php.net/reflection">Reflection API extension</a>, some of this is possible already, so why not just include it from here on out?
</p>]]></description>
      <pubDate>Tue, 20 Feb 2007 09:07:00 -0600</pubDate>
    </item>
  </channel>
</rss>
