CakeFest 2024: The Official CakePHP Conference

ReflectionClass::getNamespaceName

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

ReflectionClass::getNamespaceName名前空間の名前を取得する

説明

public ReflectionClass::getNamespaceName(): string

名前空間の名前を取得します。

パラメータ

この関数にはパラメータはありません。

戻り値

名前空間の名前を返します。

例1 ReflectionClass::getNamespaceName() の例

<?php
namespace A\B;

class
Foo { }

$class = new \ReflectionClass('stdClass');

var_dump($class->inNamespace());
var_dump($class->getName());
var_dump($class->getNamespaceName());
var_dump($class->getShortName());

$class = new \ReflectionClass('A\\B\\Foo');

var_dump($class->inNamespace());
var_dump($class->getName());
var_dump($class->getNamespaceName());
var_dump($class->getShortName());
?>

上の例の出力は以下となります。

bool(false)
string(8) "stdClass"
string(0) ""
string(8) "stdClass"

bool(true)
string(7) "A\B\Foo"
string(3) "A\B"
string(3) "Foo"

参考

add a note

User Contributed Notes 1 note

up
7
francois
12 years ago
If the object does not belong to a namespace, an empty string is returned
To Top