I often see some “programming gurus” use strange advanced syntax such as this one:
somefunction(\WP_Query $query)
{
....
}
This is a piece of php code. You know, usually php does not require class name before function arguments. You expect the following code:
somefunction($query)
{
....
}
Why does the programming guru add the class name WP_Query before the function parameter $query? More strange, why is a backslash \ added before the class name? I cannot help worshiping the programming guru. In fact, you can remove the class name including the backslash from the code without a problem. The class name added before a function argument is called type hinting, which is used to force the caller to use a parameter value that is an instance of that class. If you do not use a value of that class when calling the defined function, php will throw a fatal error(Uncaught TypeError) and abort.
As to the backslash before the class name, it is a namespace indicator. The \ means global namespace. So, if there is another definition of WP_Query in current namespace, php will take the global one instead of the class in current namespace.