<?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 21:26:59 -0500</pubDate>
    <ttl>30</ttl>
    <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>
  </channel>
</rss>
