Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<ReflectionConstant::getNameReflectionConstant::getShortName>
^ReflectionConstantLast updated: Mon, 26 Oct 2026

ReflectionConstant::getNamespaceName

(PHP 8 >= 8.4.0)

ReflectionConstant::getNamespaceName — Gets namespace name

Description

public function ReflectionConstant::getNamespaceName(): string

Gets the namespace name of the constant.

Parameters

This function has no parameters.

Return Values

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

Examples

Example #1 ReflectionConstant::getNamespaceName() example

<?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:

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

<ReflectionConstant::getNameReflectionConstant::getShortName>
^ReflectionConstantLast updated: Mon, 26 Oct 2026