posts – Why is a wp function used in current PHP namespace’s callback not resolved to global scope?


Imagine the following script:

namespace MySpace;

class MyClass {

  public static function execute() {
    // Do something


I’m now calling this function at the top of the page template, before any HTML. The problem I get is that wp resolves the post_exists function to the namespace instead of falling back to the global scope, where wp functions are usually recognized in such cases.

So I actually get a PHP error saying Call to undefined function MySpace\post_exists(), why is that so? Is, at that moment, before the document head, the wp core not initiated, or something similar? Never experienced this bug so far…

DevelJoe 2 years 2022-04-04T19:08:55-05:00 0 Answers 0 views 0

Leave an answer