<?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 23:35:16 -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[Lorna Mitchell's Blog: ArrayAccess vs ArrayObject]]></title>
      <guid>http://www.phpdeveloper.org/news/16867</guid>
      <link>http://www.phpdeveloper.org/news/16867</link>
      <description><![CDATA[<p>
<i>Lorna Mitchell</i> has a new post to her blog <a href="http://www.lornajane.net/posts/2011/arrayaccess-vs-arrayobject">explaining ArrayObject and ArrayAccess</a> and how each is used.
</p>
<blockquote>
I help people qualify for <a href="http://www.zend.com/services/certification/">Zend Certification</a> and in the last few months I've had questions about both <a href="http://php.net/manual/en/class.arrayaccess.php">ArrayAccess</a> and <a href="http://php.net/manual/en/class.arrayobject.php">ArrayObject</a>. This post is an attempt to illuminate both. In very simple terms, ArrayAccess is an interface, which you can implement in your own objects; ArrayObject, on the other hand, is a class, which you can either use or extend.
</blockquote>
<p>
She give an example of ArrayAccess - a simple class that implements it to make it work like an array. For ArrayObject, she describes some of the things it comes with, including automatically implementing the ArrayAccess, Countable and Traversable <a href="http://www.php.net/manual/en/reserved.interfaces.php">interfaces</a> making it a "more powerful array" type.
</p>]]></description>
      <pubDate>Fri, 16 Sep 2011 09:16:37 -0500</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>
  </channel>
</rss>
