src/Reflection/ReflectionClass.php
public function getNamespace(): string
    {
        // Check cache.
        if (null === $this->namespace) {
            $tokens = $this->getTokenStream();
            // Find namespace token
            try {
                $loc = $tokens->scan(0, [T_NAMESPACE]);
            } catch (\OutOfBoundsException $e) {
                return $this->namespace = '';
            }

            // Get the next token (start with namespace)
            if ($loc !== null) {
                $loc = $tokens->next($loc);
            }

            // If the start of the namespace is found,
            // parse it, otherwise save empty namespace.
            $this->namespace = '';
            if ($loc !== null) {
                $this->namespace = $this->parseNamespace($loc);
            }
        }

        return $this->namespace;
    }
public function getNamespace(): string
    {
        // Check cache.
        if (null === $this->namespace) {
            $tokens = $this->getTokenStream();
            // Find namespace token
            try {
                $loc = $tokens->scan(0, [T_NAMESPACE]);
            } catch (\OutOfBoundsException $e) {
                return $this->namespace = '';
            }

            // Get the next token (start with namespace)
            if ($loc !== null) {
                $loc = $tokens->next($loc);
            }

            // If the start of the namespace is found,
            // parse it, otherwise save empty namespace.
            $this->namespace = '';
            if ($loc !== null) {
                $this->namespace = $this->parseNamespace($loc);
            }
        }

        return $this->namespace;
    }
public function getNamespace ( ) : string { // Check cache. if ( null === $ this -> namespace ) { $ tokens = $ this -> getTokenStream ( ) ; // Find namespace token try { $ loc = $ tokens -> scan ( 0 , [ T_NAMESPACE ] ) ; } catch ( \ OutOfBoundsException $ e ) { return $ this -> namespace = '' ; } // Get the next token (start with namespace) if ( $ loc !== null ) { $ loc = $ tokens -> next ( $ loc ) ; } // If the start of the namespace is found, // parse it, otherwise save empty namespace. $ this -> namespace = '' ; if ( $ loc !== null ) { $ this -> namespace = $ this -> parseNamespace ( $ loc ) ; } } return $ this -> namespace ; }
Returns the namespace of the class in this file or an empty string if no
namespace was declared.

@return string
Returns the namespace of the class in this file or an empty string if no namespace was declared .