Access WP_REST_Server from within plugin namespace
Question
I am new to OOP and developing plugins. I have developed a plugin using the Plugin-Boilerplate with namespace. I expanded the boilerplate to include a REST folder and class so I could create custom routs/endpoints. It is working; however I cannot use the WP_REST_Server object. I get the following error: ..class-wp-rest-server.php does not exist.From my limited knowledge of oop my guess I it is not in my namespace. But how do I include/access it? My guess is there is a simple mechanism that is obvious to experienced OOPs. Thanks.
Solution
WordPress (version 5.0) doesn't use namespaces for it's classes, so try to use the global one:
\WP_REST_Server
to avoid assuming it's in your custom namespace.
One of the reason for this is that WordPress supports PHP 5.2.4+ that doesn't support namespaces. The minimum is PHP 5.3.3+, if I remember correctly, to support it.
Later this year (2019) WordPress plans to bump the minimum required PHP version to 5.6 and then to 7 at the end of the year. So after that, WordPress namespaces could be possible, but I'm not aware of any such planned changes though :-)