Page 1 of 1

Namespace Question

Posted: Fri Jul 03, 2009 8:15 am
by thomas777neo
Good Day

I am messing around with the new stuff in the php5.3.0 release, specifically namespaces.

namespace.php

Code: Select all

<?php
namespace Pro7\Amphibian;
 
class evolution
{
    function connect($dbConn)
    {
        return $dbConn;
    }
}
 
$evolution = new evolution; // za\co\pro7\amphibian\evolution
 
var_dump($evolution);
 
$namespace = __NAMESPACE__;
echo "\n\$namespace:$namespace\n";
 
$connect = $evolution-> connect("mysql");
echo "\$connect:$connect\n";
?>
useNamespace.php

Code: Select all

 
<?php
use Pro7\Amphibian\evolution as evolution;
 
$obj = new evolution;
?>
 
I am getting an error in useNamespace.php when trying to create a new object of the class in my namespace.
C:\php5.3.0>php useNamespace.php
PHP Fatal error: Class 'Pro7\Amphibian\evolution' not found in C:\php5.3.0\useN
amespace.php on line 4
I am not sure what I am doing incorrectly. I think that my concept of the global availability of the namespace might be incorrect.

Re: Namespace Question

Posted: Mon Jul 06, 2009 2:33 am
by thomas777neo
Thanks for your feedback.

Well, it is unfortunate that you need to include the namespace file :banghead:

As it does defeat the point a bit.