include classes without namespaces into namespace php

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:

<?php 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 Validate

When using the class!

This page has been viewed 5692 times. First hit: 30-Oct-2015 13:32:29
Share email, Google+, Twitter, Facebook.
comments powered by Disqus