-
Horizontal reusability with traits
By Ryan on 22 August 2011
Although PHP allows classes to implement more than one interface, it does not support multiple inheritance. Lack of multiple inheritance can lead to code duplication in certain situations, which is contrary to the goals of reusable object-oriented programming. Here I explore a couple of these situations and traits, a new language-level feature in PHP 5.4 that has been added to address this concern. [read more]
-
Anonymous recursion in PHP
By Ryan on 08 August 2011
I've been working toward building a useful set of concepts to apply some functional programming techniques in PHP 5.3. Yes, _functional_ programming in PHP. In this article, I explore the concept of anonymous recursion, something that becomes important in situations where we are using anonymous functions to solve problems that are well suited to a recursive approach. [read more]
-
Anonymous functions and closure in PHP
By Ryan on 15 July 2011
PHP 5.3 introduced function literals to the language, providing big benefits in the form of syntax and readability when using and creating functions that accept other functions as arguments. However, the introduction of anonymous functions was paired with another useful language construct which allows us to close over local variables in the same scope as the anonymous function, creating a closure. [read more]
-
Simple performance profiling in PHP 5.3
By Ryan on 13 June 2011
PHP's standard library makes it pretty easy to whip up a quick set of timing functions to wrap around your code. Maybe I'm jaded by ruby's blocks, but I would love to see that my profiling code is getting everything I want and _only_ those things I want. So I decided to sit down and whip up something quick and simple to alleviate my neurosis. [read more]
-
nanoc websites with binary data
By Ryan on 07 June 2011
nanoc is a wonderful little gem that uses Ruby/ERB to create statically-generated websites. It saves you the trouble of firing up a database connection on every request while still allowing you the flexibility of Ruby to generate your sites. I wrote a quick walkthrough to bridge the gap between what I learned through the nanoc documentation and what I needed to know to finish converting my own site. [read more]
-
Late-game unit testing
By Ryan on 07 April 2011
Sometimes I need to add features to old projects for which I didn't write unit tests. Sometimes I neglect to write unit tests during development in new projects. Oops. In situations like these, what are some approaches to then going back and adding "necessary" test coverage? [read more]
-
Decorating PHP classes without a common ancestor
By Ryan on 15 March 2011
The decorator pattern is used to extend the public interface of an object at runtime. Because of this, it exposes a nice way to modify the behavior of objects instantiated from classes in other libraries, even ones to whose source you may not have access. The decorator pattern is commonly described as a pair of classes--a component and a decorator--which derive from a common ancestor. However, we relax this restriction using PHP language features. [read more]