<?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>Sun, 12 Feb 2012 17:12:19 -0600</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[PHPBuilder.com: PHP Arrays: Advanced Iteration and Manipulation]]></title>
      <guid>http://www.phpdeveloper.org/news/17238</guid>
      <link>http://www.phpdeveloper.org/news/17238</link>
      <description><![CDATA[<p>
In <a href="http://www.phpbuilder.com/columns/php_arrays/PHP_Arrays_12-8-2011.php3">this new tutorial</a> from PHPBuilder.com, <i>Jason Gilmore</i> shows you some of the more advanced things you can do with arrays in PHP (specifically in the areas of iterating through them and manipulating their contents).
</p>
<blockquote>
Sporting more than 70 native array-related functions, PHP's array manipulation capabilities have long been one of the language's most attractive features. [...] There are however many array-related tasks which ask a bit more of the developer than merely knowing what part of the manual one needs to consult. Many such tasks require a somewhat more in-depth understanding of the native features, or are possible only when a bit of imagination is applied to the problem.
</blockquote>
<p>
In his examples he shows how to do things like sorting a multi-dimensional array, iterating recursively (with the help of a <a href="http://www.php.net/manual/en/class.recursivearrayiterator.php">RecursiveArrayIterator</a>), converting an object to an array and doing "natural" sorting on an array's contents.
</p>]]></description>
      <pubDate>Fri, 09 Dec 2011 12:50:11 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Joshua Thijssen's Blog: SPL: Using the iteratorAggregate interface]]></title>
      <guid>http://www.phpdeveloper.org/news/17216</guid>
      <link>http://www.phpdeveloper.org/news/17216</link>
      <description><![CDATA[<p>
<i>Joshua Thijssen</i> has a <a href="http://www.adayinthelifeof.nl/2011/12/04/spl-using-the-iteratoraggregate-interface/">recent post</a> spotlighting a part of the <a href="http://php.net/spl">Standard PHP Library</a> (SPL) that implements that Traversable interface, the <a href="http://www.php.net/iteratorAggregate">IteratorAggregate</a> interface.
</p>
<blockquote>
Together with its more famous brother "Iterator", they are currently the two only implementations of the "Traversable" interface, which is needed for objects so they can be used within a standard foreach() loop. But why and when should we use the iteratorAggregate?
</blockquote>
<p>
He answers his question with an example - a book that contains chapters. With a normal iterator you'd have to define standard functions (like valid, rewind or key). Using the IteratorAggregate you can push items into an internal array (like chapters in a book) and call a "getIterator" method to get this set. He also takes it one step further and shows implementing the "Count" interface to make it easier to get a total count of the items in the iterator. Sample code is included to help clarify.
</p>]]></description>
      <pubDate>Tue, 06 Dec 2011 08:28:45 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Jake Smith's Blog: Callback Filter Iterator in PHP 5.3/5.4]]></title>
      <guid>http://www.phpdeveloper.org/news/17202</guid>
      <link>http://www.phpdeveloper.org/news/17202</link>
      <description><![CDATA[<p>
<i>Jake Smith</i> has a new post to his blog today about a feature included in PHP's <a href="http://php.net/spl">Standard PHP Library</a> that you might have overlooked - <a href="http://jakefolio.com/2011/12/callback-filter-iterator-in-php/">the FilterIterator's callback functionality</a>.
</p>
<blockquote>
The Filter Iterator is probably my second favorite iterator, next to Directory Iterator.  There are many great use cases for the Filter Iterator, and when you do filter the original data is left untouched. A Filter Iterator is really simple to use, create a class that extends FilterIterator and adjust the accept method to meet your criteria.  This is great and all, but having the ability to create filter iterators on the fly, ones that won't be used application wide, without having to create a class is even better.
</blockquote>
<p>
He includes a bit of code defining a FilterCallbackIterator class with a "callback" parameter passed into the constructor (in his case, a closure). Also included is some sample code of it in use - handling an array (well, ArrayIterator) with a simple true/false check on the current array value. You can find out more about this functionality in <a href="http://www.php.net/manual/en/class.callbackfilteriterator.php">the PHP manual</a>.
</p>]]></description>
      <pubDate>Fri, 02 Dec 2011 08:44:34 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Davey Shafik's Blog: Faster Arrays]]></title>
      <guid>http://www.phpdeveloper.org/news/17091</guid>
      <link>http://www.phpdeveloper.org/news/17091</link>
      <description><![CDATA[<p>
In <a href="http://daveyshafik.com/archives/30320-faster-arrays.html">this new post</a> to his blog <i>Davey Shafik</i> looks at an alternative to the traditional <a href="http://php.net/arrays">arrays</a> most scripts use - something a little faster and more specific: <a href="http://php.net/splfixedarray">SplFixedArray</a>, part of the <a href="http://php.net/spl">Standard PHP Library</a> included with every release.
</p>
<blockquote>
The SplFixedArray class provides a super-fast, fixed size array implementation. There are some limitations however, first you must use numeric keys and secondly you cannot use anonymous assignment (i.e. $array[] = 'value';). You'll notice one requirement was missing, that it should have a fixed size. While having a fixed size is what will bring you the speed increase it's actually not a requirement that the size be fixed.
</blockquote>
<p>
Because of these restrictions, the SplFixedArray is faster than its cousin - between 20 and 40 percent faster, depending on the size of the array. He includes a few snippets in the the post - one showing how he benchmarked the differences against simple arrays and another showing a more advanced example with another SPL type, a <a href="http://php.net/filteriterator">FilterIterator</a>.
</p>]]></description>
      <pubDate>Mon, 07 Nov 2011 08:54:58 -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[James Morris' Blog: Removing Dependencies with the Observer Pattern (SplObserver, SplSubject)]]></title>
      <guid>http://www.phpdeveloper.org/news/16356</guid>
      <link>http://www.phpdeveloper.org/news/16356</link>
      <description><![CDATA[<p>
<i>James Morris</i> has a new post to his blog talking about a way he's found to remove dependencies from parts of your code <a href="http://blog.jmoz.co.uk/removing-dependencies-with-the-observer-patte">by using the Observer pattern</a> (specifically with the SplObserver and SplSubject components of PHP's SPL libraries).
</p>
<blockquote>
Working on a symfony app, you usually have a mix of domain objects that are used by symfony actions, interspersed with symfony specific code such as logging and sfContext type stuff.  A common bad practice I see is symfony specific code peppered inside of domain objects that could be used elsewhere (such as inside of a Zend app or a script from the cli) but now can't as they're coupled to the symfony code. One way you can remove an unwanted dependency is to use the Observer pattern - the dependency is pushed from inside the subject object to the client code that initialises the subject.
</blockquote>
<p>
He sets up a scenario where a symfony action hits a web service and there's a dependency on two other types of objects (a service and transport object). He starts with the code for this method and gradually refactors out those two dependencies, removing an sfContext call from inside the service client and adds attach/detach/notify methods to implement the SplObserver on the class.
</p>]]></description>
      <pubDate>Wed, 18 May 2011 12:05:43 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jani Hartikainen's Blog: How to use built-in SPL exception classes for better error handling]]></title>
      <guid>http://www.phpdeveloper.org/news/16310</guid>
      <link>http://www.phpdeveloper.org/news/16310</link>
      <description><![CDATA[<p>
On his blog today <i>Jani Hartikainen</i> looks at how you can <a href="http://codeutopia.net/blog/2011/05/06/how-to-use-built-in-spl-exception-classes-for-better-error-handling/">use the SPL exception types</a> to allow for better overall error handling in your application. Things like BadMethodCallException and OutOfBoundsException make the errors much more descriptive.
</p>
<blockquote>
Since PHP 5, there has been a bundle of built-in exceptions - the "SPL exceptions" - in PHP. However, the documentation for these classes is quite lacking in examples, and it can be difficult to understand when you should be using them. The short answer is always. 
</blockquote>
<p>The list of exception types he recommends include:</p>
<ul>
<li>BadMethodCallException
<li>DomainException
<li>LengthException
<li>OutOfRangeException
<li>UnexpectedValueException
</ul>
<p>
For each he gives an example usage of it, sometimes including a bit of code to illustrate. 
</p>]]></description>
      <pubDate>Mon, 09 May 2011 08:47:12 -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>
  </channel>
</rss>

