wireClassNamespace() function

Get namespace for given class

Please note this method is and thus not intended to be called directly.

Available since version 3.0.150.

Example

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' }

Internal usage

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

Arguments

NameType(s)Description
$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.255