PHP如何获取类方法参数的名称空间?

PHP如何获取类方法参数的名称空间?,php,parameters,namespaces,Php,Parameters,Namespaces,您好,我尝试了很多方法来捕捉参数函数的名称空间,但什么都没有 public function table(Homes $homes) { // <---------- Homes return $homes->get('home'); } 公共函数表(Homes$Homes){//get('home'); } 我尝试使用ReflectionClass,但只提供名称$homes,而不是homes名称空间。如果我理解正确,您需要使用名称空间获取类名。。。 在PHP中,命名空间

您好,我尝试了很多方法来捕捉参数函数的名称空间,但什么都没有

public function table(Homes $homes) { // <---------- Homes
    return $homes->get('home');
}
公共函数表(Homes$Homes){//get('home');
}

我尝试使用ReflectionClass,但只提供名称$homes,而不是homes名称空间。

如果我理解正确,您需要使用名称空间获取类名。。。 在PHP中,命名空间是类名的一部分。还有一个简单的内置函数get_class($object)

有可能:

$method         = new ReflectionMethod('classDeclaringMethodTable', 'table');

// ReflectionMethod::getParameters() returns an *array*
// of ReflectionParameter instances; get the first one
$parameter      = $declaringMethod->getParameters()[0];

// Get a ReflectionClass instance for the parameter hint
$parameterClass = $parameter->getClass();
然后在这一点上,这完全取决于你想要什么

// Returns ONLY the namespace under which class Homes was declared
$parameterClass->getNamespaceName();

// Returns the fully qualified class name of Homes
// (i.e. namespace + original name; it may've been aliased)
$parameterClass->getName();

我使用了多个变量使其更容易理解,但它可以很容易地成为带有方法链接的一行程序。

Homes
不是“名称空间”,而是一个类名
get_class($homes)
No我试图得到:$reflector=newreflectionclass('System\Classes\Architecture');我想在创建新家园之前用反射设置对象是的,这是一个名称空间家园这是一个名称空间“Class System\Classes\Architecture\Homes”@JohnStamoutsos请编辑您的问题,并尝试澄清您正试图实现的目标。现在,你的问题和你的评论在我看来很不一致,我真的不理解你的问题。如果您试图获取一个没有类名本身的类的名称空间,那么只需
(newreflectionclass($home))->getNamespaceName()不,我试着得到:$reflector=newreflectionclass('System\Classes\Architecture');我想用反射设置对象,宝贝,就是这样!