php8.5
Home/ Manual/ reflection / reflectionconstant/ ReflectionConstant::getNamespaceName

ReflectionConstant::getNamespaceName

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Gets namespace name

Description

ReflectionConstant::getNamespaceName(): string

Gets the namespace name of the constant.

Parameters Parameters

Return Values

The namespace name, or an empty string for the global namespace.

Examples

ReflectionConstant::getNamespaceName example

php
<?php
namespace Foo {
   const BAR = 'bar';
   var_dump((new \ReflectionConstant('Foo\BAR'))->getNamespaceName());
}

namespace {
   const BAR = 'bar';
   var_dump((new \ReflectionConstant('BAR'))->getNamespaceName());
}
?>

The above example will output:

output
string(3) "Foo"
string(0) ""

Source: reference/reflection/reflectionconstant/getnamespacename.xml · from the official PHP manual (php/doc-en)