Getting an “Undefined constant '__NAMESPACE__'” error in PhpStorm even after a namespace has been defined

Viewed 259

I am completely new to PHP and I am trying to teach myself here and play with the prospect of creating my very own WordPress theme - YAY!

Anyway, I am running into a roadblock here and I am not certain if this is just the IDE I am using (PhpStorm), or if it is something else.

Here is what I am seeing in PhpStorm:

enter image description here

When I use Kint, it shows that the namespace is defined as shown in the screenshot above (namespace SavvyPro\Sandbox):

enter image description here

Here is the complete code:

namespace SavvyPro\Sandbox;

add_action('loop_start', __NAMESPACE__ . '\process_the_string');
function process_the_string()
{
    $current_user = wp_get_current_user();

    render_user_message($current_user->user_firstname, get_the_ID());
}

function render_user_message($first_name, $post_id)
{
    d("My name is {$first_name}.");

    ddd("The post ID is {$post_id}.");
}

Here is the version of PhpStorm I am currently running:

enter image description here

I am certain it is something quite simple for you PHP gurus out there, but since I am such a noob, it's a bit of a brain twister for me.

Any help on this is of course greatly appreciated.

Thank you all!

1 Answers

I emailed JetBrains support and they got back to me with the fix and it is exactly what @LazyOne mentioned in the comments section above.

I simply deleted the following folder on my Mac and it resolved the issue:

~Library/Caches/JetBrains/PhpStorm2020.2

Related