PhpRiot
Follow phpriot on Twitter
Sponsored Link
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Taking advantage of PHP namespaces with older code

Note: This article was originally published at Planet PHP on 31 January 2011.
Planet PHP

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.

  1. use Sabre_DAV_Auth_Backend_PDO as AuthBackend;
  2. use Zend_Controller_Action_Helper_AutoComplete_Abstract as AutoComplete;
  3. $backend = new AuthBackend();
  4. ?

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