SOLID PHP & Code Smells – Part 2: Open / Closed Principal

This is the presentation I gave last night to the GTAPHP Meetup Group about the Open/Closed Principal – the ‘O’ in SOLID. The idea is to provide strategies for code re-use which allow you to leave your debugged code alone when extending it for new features. We look at the classical OOP inheritance pattern, the Template Method pattern, the Data Mapper pattern and the Strategy pattern in this presentation.

Here are my own notes I used during the presentation so I wouldn’t get lost with my code edits:

You can work through all the key checkpoints in the refactoring process by following the commits on github.


SPIL: A Non-Framework Proposal for PHP

Update: Now on github.

I’ve just finished listening to the second /dev/hell podcast from Chris (my GTAPHP co-organizer) and Ed where they discussed a big problem with frameworks in PHP.  They’re too big, and its too difficult to extract only the functionality you want without bringing over a whole pile of dependencies at the same time.  I’ve been unhappy about the same kind of problem.  I’ve been looking for a new CMS, and it drives me nuts that big CMS’s include their own frameworks instead of building on existing frameworks.  There are exceptions, but generally a CMS includes its own framework.

Listening to Chris and Ed got me thinking about this, and about another pet peeve of mine with PHP frameworks.  They don’t tend to make good use of class interfaces, depending instead on concrete classes.  If they worked with interfaces then it would be easier for frameworks to share common code, and for CMS’s to build on common code.  I have a modest proposal to address this problem…

Read more…

SOLID PHP & Code Smells – Part 1: Single Responsibility Principle

Update: Now on github

These are the slides from my presentation to the GTA PHP Meetup Group last night. Thanks to everyone who attended for your questions, and for hanging on with me while I debugged some unexpected issues while refactoring. I will post again when I have the source up on git if you want to try your own hand the same changes, or your own changes.

Traits in PHP 5.4

Traits in my opinion are the greatest thing to happen to PHP since PHP 5.  They provide a way to re-use code between otherwise unrelated classes.  I’m giving a talk on traits at tomorrow night’s GTA-PHP Meetup with just a few slides:

The bulk of the talk will be actually trying some demos I’ve prepared. You can get them from my github. I’ve included README.txt files which describe what each demo is about in case you can’t make it out to the meetup, or you’ve found this after the fact.

Introduction to MySQL

On top of my Cloud track to TEC 20ii I’m doing two of the LAMP track sessions.  Here are the slides for my introduction to MySQL:

Introduction to MySQL

If you’re new to SQL this might be useful to you.  My other LAMP track session is on PHP security.  I should have those slides up tomorrow.

Overview of Cloud Services

Here are the slides from my first talk at TEC 20ii which introduces the Cloud Programming technology track.  If you’re still trying to figure out what the heck this “Cloud” thing is then this might help:

Overview of Cloud Services

As always, feel free to provide feedback in the comments section if you have any suggestions or corrections.

Cloud Programming: JavaScript Applications

JavaScript Applications under the banner of Cloud?  Maybe a stretch, but I’ve included a session on this topic in my cloud track at TEC 20ii.  I think JavaScript application development belongs in the world of cloud computing for two reasons.  JavaScript can offload work from the server to the client, and because you can create applications which maintain their state you can reduce the number of HTTP requests, and the size of each request.  On top of that, ubiquitous access is part of many “What is the Cloud” definitions, and the most supported language for developing mobile applications with HTML 5.

With that in mind, here are my slides from my talk on JavaScript at TEC20ii:

Cloud Programming: JavaScript Applications

If you’re following along, here are links the the source referenced in the slides:


Cloud Programming: Introduction to Node.js

Out of all the technologies I’ve been looking at for “what’s next”, Nodejs is the one I’m most excited about. Only a few months ago I was guessing that Node.js would be ready for prime time in about three years. I was figuring on another year for stability and security issues to settle down, another year for the API’s and libraries to be in good shape, and one more year for the technology to prove itself in real world scenarios. It may not be 100% ready for every problem but its a lot further along than I had imagined in such a short time.

I attended a recent TechTalksTO event where James Duncan from Joyent spoke about their use of node.js.  He said that Joyent is already using node.js in production extensively, and happily.  Joyent also provides free node.js hosting for developers who want to get their feet wet without setting up a server.

Here are my slides for the Introduction to Node.js talk at TEC 20ii:

Cloud Programming: Introduction to Node.js

If you’re following along, here are links to the source code:


Cloud Programming: Introduction to CouchDB

CouchDB is my personal favorite of the new breed of “NoSQL” databases.  Here are my slides for my CouchDB presentation at the TEC 20ii conference:

Cloud Programming: CouchDB

If you’re following along you might want to copy and paste from these examples:

Our First Design Document’s Stub:

{ "people": { "map": "function(doc) {}" } }

Our First View:

function (doc) {
if ( {
emit(, doc._rev);

Our Second View’s Stub: (pasted into the design document; slide 48)

"parties": { "map": "function(doc) {}" }

Our Second View:

function (doc) {
if ( {
emit(, 1);

Our First Reduce Function:

function (key, values, rereduce) {
return sum (values);

Cloud Programming: Introduction to Google App Engine

As part of my “Cloud Programming” track at TEC 20ii I’m presenting an introduction to Google App Engine.  I’ll be making any updates / corrections to the Google Presentation here:

Introduction to Google App Engine

These slides cover installing Google App Engine on Windows and writing your first application.  It includes a very simple introduction to the datastore.

Warning:  Don’t build a hit counter this way – this is just a simple way to introduce App Engine, but should not be used in production.  Counting records is a slow operation in distributed databases, and this will actually read each record to get the count.  There are better but more complicated ways to do this.


application: myfirstapp
version: 1
runtime: python
api_version: 1

– url: .*
script: snippet (broken):

class MainHandler(webapp.RequestHandler):
def get(self):
hit = HitInfo(useragent = self.request.headers['User-Agent'])
hits = HitInfo.all().count()
self.response.out.write('Hello number '+hits) snippet (corrected):

class MainHandler(webapp.RequestHandler):
def get(self):
hit = HitInfo(useragent = self.request.headers['User-Agent'])
hits = HitInfo.all().count()
self.response.out.write('Hello number '+str(hits))