Home Account

include classes without namespaces into namespace php

18-Dec-2014 14:51:00 dennis

Tags: php pear

Got the following error when importing a PEAR class (Validate) into my namespace diversen

Cannot redeclare class Validate 

In order to include a 3. part class without namespaces (like PEAR classes) into your namespace you can to do the following:


namespace diversen; 

include_once 'Validate.php';

// to prevent Fatal error:
// Cannot redeclare class Validate 
// use Validate as e.g. pearValidate; 

use Validate as pearValidate;

But is is much simpler to write:



use Validate


When using the class!