wireClassNamespace() function

Get namespace for given class

Available since version 3.0.150.


echo wireClassNamespace('Page'); // returns: "\ProcessWire\"
echo wireClassNamespace('DirectoryIterator'); // returns: "\"
echo wireClassNamespace('UnknownClass'); // returns "" (blank)

// Specify true for 2nd argument to make it include class name
echo wireClassNamespace('Page', true); // outputs: \ProcessWire\Page

// Specify true for 3rd argument to find all matching classes
// and return array if more than 1 matches (or string if just 1):
$val = wireClassNamespace('Foo', true, true);
if(is_array($val)) {
  // 2+ classes found, so array value is returned
  // $val: [ '\Bar\Foo', '\Foo', '\Baz\Foo' ]
} else {
  // string value is returned when only one class matches
  // $val: '\Bar\Foo'


// basic usage
$string = wireClassNamespace($className);

// usage with all arguments
$string = wireClassNamespace($className, bool $withClass = false, bool $strict = false);


classNamestring, object
withClass (optional)bool

Include class name in returned namespace? (default=false)

strict (optional)bool

Return array of namespaces if multiple match? (default=false)

Return value

string array

Returns one of the following:

  • String of \Namespace\ (leading+trailing backslashes) if namespace found.
  • String of \ if class in root namespace.
  • Blank string if unable to find namespace for class.
  • Array of namespaces only if $strict option is true AND multiple namespaces were found for class.
  • If the $withClass option is true, then return value(s) have class, i.e. \Namespace\ClassName.

Functions methods and properties

API reference based on ProcessWire core version 3.0.163

Twitter updates

  • Weekly update – 28 August 2020 – New secure files option defined per-template: More
    28 August 2020
  • ProcessWire 3.0.165 core updates (master and dev branch) and reCAPTCHA for FormBuilder module— More
    21 August 2020
  • What's coming in ProcessWire 3.0.165, plus a brief preview ProCache and FormBuilder versions coming within the next couple of weeks— More
    14 August 2020

Newest forum posts

Latest news

  • ProcessWire Weekly #330
    In the 330th issue of ProcessWire Weekly we'll take a quick peek at the new release of the FormBuilder module, cover some recent form highlights, and more. Read on!
    Weekly.pw / 5 September 2020
  • ProcessWire 3.0.164 new master version
    This week we’re proud to announce the newest ProcessWire master version 3.0.164. Relative to the previous master version (3.0.148) this version adds a ton of new and useful features and fixes more than 85 issues, with more than 225 commits over a period of 7 months.
    Blog / 7 August 2020
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani