php8.5
Home/ Manual/ reflection / reflectionclass/ ReflectionClass::inNamespace

ReflectionClass::inNamespace

PHP function Edit on GitHub ✎

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

Checks if in namespace

Description

ReflectionClass::inNamespace(): bool

Checks if this class is defined in a namespace.

Parameters Parameters

Return Values

Returns true if the class is in specified namespace or false otherwise.

Examples

ReflectionClass::inNamespace example

php
<?php
namespace A\B;

class Foo { }

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

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

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

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

The above example will output:

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

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

See Also

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