<?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>Sat, 25 May 2013 22:52:57 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Jeremy Cook's Blog: Implementing the ArrayAccess Interface]]></title>
      <guid>http://www.phpdeveloper.org/news/17490</guid>
      <link>http://www.phpdeveloper.org/news/17490</link>
      <description><![CDATA[<p>
<i>Jeremy Cook</i> is back with the next part of his series looking at the handy features PHP's <a href="http://php.net/spl">SPL</a> provides. In <a href="http://jeremycook.ca/2012/01/22/implementing-the-arrayaccess-interface/">this new post</a> he looks at the ArrayAccess interface and how it can make your data more accessible to PHP's own array handing functions.
</p>
<blockquote>
ArrayAccess allows you to treat an object that implements it as if it is an array for the purposes of setting, unsetting and retrieving data from it. Please note the emphasis in the last sentence! ArrayAccess does not make an object behave like an array in any other way. If you pass an object that implements ArrayAccess to a PHP array function such as in_array() you'll still get an error. This will become a little clearer with some of the examples below.
</blockquote>
<p>
He shows what you'll need to use this interface in your class - implementing the interface and defining a set of four methods to get/set and check for the value in your array. He includes a practical example of pulling data back from an API and wrapping it in a class to make accessing it simpler (also implementing the Countable interface as well, see the <a href="http://jeremycook.ca/2012/01/01/using-the-countable-interface/">previous post</a> for more on that). Code is include to illustrate how it can be used.
</p>]]></description>
      <pubDate>Thu, 02 Feb 2012 13:56:43 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Jeremy Cook's Blog: Using the Countable Interface]]></title>
      <guid>http://www.phpdeveloper.org/news/17354</guid>
      <link>http://www.phpdeveloper.org/news/17354</link>
      <description><![CDATA[<p>
In a recent post to his blog <i>Jeremy Cook</i> has a tutorial <a href="http://jeremycook.ca/2012/01/01/using-the-countable-interface/">about using the Countable interface</a> (part of the SPL) in your objects to make them play nicely with functions like <a href="http://php.net/count">count</a>.
</p>
<blockquote>
PHP provides a number of predefined interfaces and classes that can really make your life as a developer easier but which are often overlooked. The functionality offered by the <a href="http://ca2.php.net/manual/en/book.spl.php">Standard PHP Library (SPL)</a> and the <a href="http://ca2.php.net/manual/en/reserved.interfaces.php">predefined interfaces</a> is extremely cool and very powerful but very underutilized. [...] I thought I'd write a few articles with examples of how I've used these classes and interfaces in the hope that someone would find it useful. I'd love it if people felt like commenting with their own examples too. I'll start with a quick look at the Countable interface.
</blockquote>
<p>
He includes sample code for classes using the Countable interface and defining the custom "count()" method inside. This method lets you define how the object will behave when something like <a href="http://php.net/count">count</a> is called on it. His examples show returning the number of items in a private variable, determining the state of an object and including logic to only find valid data (like from a database table).
</p>]]></description>
      <pubDate>Thu, 05 Jan 2012 14:39:05 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Implementing the ArrayAccess Interface - PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16483</guid>
      <link>http://www.phpdeveloper.org/news/16483</link>
      <description><![CDATA[<p>
In the first part of a new series over on DevShed.com, they introduce the concept of "segregated interfaces" and show how to use them <a href="http://www.devshed.com/c/a/PHP/Segregated-Interfaces-in-PHP/1/">to work with collections of arrays</a> (using interfaces that are a part of the <a href="http://php.net/spl">SPL</a>).
</p>
<blockquote>
To start illustrating why segregated interfaces are really useful, in the lines to come I'm going to build an example that will recreate the scenario described in the introduction. Basically, what I want to achieve here is to construct a custom countable array collection.
</blockquote>
<p>
He shows the basic class structure needed to emulate a countable array in an object by implementing the "Countable" interface. He adds in the "Iterator" interface to allow you to work with the dataset like an array - progressing through it, rewinding to the beginning and checking to see if a value exists. Finally, they add the "ArrayAccess" interface to the class that boosts it with even more features like the ability to grab things by specific keys (numeric or string). The finish the article off with an example of an ArrayCollection object and how it can be looped through using a <a href="http://php.net/foreach">foreach</a>.
</p>]]></description>
      <pubDate>Fri, 17 Jun 2011 08:58:04 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[SitePoint PHP Blog: Sophisticated Object Iterators in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16301</guid>
      <link>http://www.phpdeveloper.org/news/16301</link>
      <description><![CDATA[<p>
Following up on their earlier <a href="http://phpdeveloper.org/news/16267">simple object iterators</a> post, the SitePoint PHP blog is back with a look at <a href="http://blogs.sitepoint.com/php-object-iterators/">more sophisticated iterators</a> you can use to work with database record objects.
</p>
<blockquote>
In my previous post, <a href="http://blogs.sitepoint.com/php-simple-object-iterators">Simple Object Iterators in PHP</a>, we discovered how to iterate over array items defined within an object using a <a href="http://php.net/manual/en/control-structures.foreach.php">foreach loop</a>. However, what if you need to iterate over items which are not stored in an array, e.g. records from a database or lines of text read from a file?
</blockquote>
<p>
He shows how to create a script that pulls in the users from a database object (PDO, in this case) and implements the Countable and Iterator interfaces. These interfaces give it some special methods that can give counts of the results and help you iterate through the results - current, rewind, next and valid. 
</p>]]></description>
      <pubDate>Thu, 05 May 2011 12:54:59 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Havard Eide's Blog:  Countable]]></title>
      <guid>http://www.phpdeveloper.org/news/10739</guid>
      <link>http://www.phpdeveloper.org/news/10739</link>
      <description><![CDATA[<p>
In a <a href="http://eide.org/2008/07/30/countable/">new post</a> <i>Havard Eide</i> looks at the creation of a Countable interface that can be used in any application:
</p>
<blockquote>
Today I will look at the Countable interface, it has a single function that needs to be implemented: count(), by implementing this you can ensure that there is a count() function ready to use on any given class that implements it. The Countable interface is used in other places in the SPL as well: the ArrayIterator and ArrayObject classes implements this interface ( and SqliteResult if present ).
</blockquote>
<p>
In his code examples he shows simple methods for returning the count() of a property, but notes that the real power of it comes in the ability to manipulate the number returned from the call based on other parameters (or filtering).
</p>]]></description>
      <pubDate>Fri, 01 Aug 2008 10:23:28 -0500</pubDate>
    </item>
  </channel>
</rss>
