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.