Pragmatism in the real world

A primer on PHP namespaces

I know that there are a lot of posts now about namespaces in PHP 5.3. This is mine which is how I learnt how they work. What are namespaces? From the PHP manual: namespaces are a way of encapsulating items Hardly the most useful of definitions, but it's a starting point! A namespace is a way of grouping code that exists across multiple files without having a naming collision. That is, you can have the… continue reading.

Using Zend\Loader\Autoloader

Autoloading is the process in PHP whereby the system attempts to load a class when it is first encountered (via new or via class_exists) if it hasn't already been loaded via a require or include. Autoload works by looking for a method called __autoload or walking through any method registered with spl_autoload_register. Zend Framework 2 provides the Zend\Loader\Autoloader component for autoloading of Zend Framework and your own classes. What does it provide? The ZF2 autoloader… continue reading.

One-to-many joins with Zend_Db_Table_Select

Let's say that you want to set up a one-to-many relationship between two tables: Artists and Albums because you've refactored my ZF1 tutorial. Let's assume that an artist has many albums. These are the basic table definitions: artists table: id, artist albums table: id, artist_id, title When you list the albums, you obviously want to see the artist name rather than the id, so clearly you use a join! Assuming you're using Zend_Db_Table, the easiest… continue reading.

Two new Sublime Text 2 packages for PHP

Stuart Herbert has written two new Sublime Text packages for PHP: Additional PHP Snippets PHPUnit The best way to install these is to install Package Control first and then use shift+cmd+P -> install package. Even better, Stuart has rolled my getter/setter creation snippet into Additional PHP Snippets, so you can now have it without any hassle! Update: Also, Ben Selby has created a package for DocBlox!

Jason Grimes: Using Doctrine 2 in Zend Framework 2

Jason Grimes has posted an article showing how to use Doctrine 2 with Zend Framework 2. He uses my tutorial as the starting point which enables him to concentrate on the Doctrine integration rather than the irrelevant details about setting a ZF2 application which is excellent. He walks through 6 steps in order to do the integration: This article shows how to set up and use Doctrine 2 in Zend Framework 2, by extending Rob’s… continue reading.

Sublime Text 2 Snippet for PHP getter and setter generation

Update: This article has been superseded by Improved Sublime Text 2 PHP getter and setter generation I've been playing with Sublime Text 2 recently and have quite enjoyed how quiet my ageing laptop is when the fans aren't running due to a Java-based IDE. As with a lot of editors, Sublime Text supports snippets which are essentially text expansions of a short phrase into more text. I needed to create a few getXxx() and setXxx()… continue reading.

2011 in pictures

As I have done in 2008, 2009 and last year, I thought I'd continue my tradition of recapping my year with some photos. January PHPBNL 2011 happened in January. Also, my Mac OS X application, Daily Jotter was released onto the Mac App Store. February The first PHPucEU happened in Manchester which was great fun and, of course, the PHPUK conference in London. The biggest news for us though, was that we moved house in… continue reading.

Zend Framework 2 Beta 2 released

Zend Framework 2, Beta 2 has been released! The key new features are: Refactored Mail component Refactored Cache component MVC updates Check out Matthew's blog post for the full details. I've also updated my tutorial. This is a good time to get involved, try it out and let us know what you like/dislike.

Evan Coury: Keeping a clean GitHub fork – Part 1

Evan has posted the first of a series of articles on his blog about using git and github successfully: Let’s face it, nobody likes a dirty fork. In this series, I’ll show you some of the tricks I’ve learned over the years to successfully maintain a clean fork on GitHub for projects I actively contribute to. The first article covers creating your clone, adding remotes, keeping things up to date and working in topic branches.… continue reading.