PHP Conference Nagoya 2025

ReflectionConstant::getNamespaceName

(PHP 8 >= 8.4.0)

ReflectionConstant::getNamespaceNameGets namespace name

Description

public 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) ""
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top