2012-11-01 33 views

回答

1

如果你想在当前命名空间:

namespace MyProject; 

echo '"', __NAMESPACE__, '"'; // outputs "MyProject" 

否则你在配置文件中或者通过我想(通过应用结构的注释说明)存储...

2

试试这个例子。你可以定义一个类来处理你的电话

<?php 
namespace Example; 

#Define a classLoader object 
class Loader{ 
/** 
* Construct and set the autoloader class handler 
*/ 
public function __construct() { 
    spl_autoload_register(array($this, 'loadClass')); 
} 

/** 
* This method is called when an object is loaded 
* 
* @param string $args 
*/ 
public function loadClass($args){ 
    var_dump($args); 
    //REMOVE: this is only for killing the process 
    die; 
} 
} 

//Create your autoloader object 
new Loader(); 

//Calling some class 
new \Some\Name\Space\Example(); 

你应该得到这样的回复。

string(23) "Some\Name\Space\Example"