Taking advantage of PHP namespaces with older code

During Rob Allen's ZF2 talk at PHPBenelux an audience member shouted this really useful tip, which I thought was worth sharing.

If you're running PHP 5.3 and you have to use pesky old code that uses long class prefixes (yea, so, pretty much all PHP code out there), you can still make use of namespace features to shorten them.

use Sabre_DAV_Auth_Backend_PDO as AuthBackend;
use Zend_Controller_Action_Helper_AutoComplete_Abstract as AutoComplete;

$backend = new AuthBackend();

Might have been super obvious to most of you, but it just hadn't occurred to me.

Bad Gateway is Toronto-based team of software engineers. We build good APIs and websites.

Want to work with me on your next project?

Email us

Web mentions