PhpStorm not recognising core PHP

In case that same issue appears for PhpStorm 2020.1 or later, that's a previously reported issue and invalidating caches won't help anymore.

As described here the solution is:

  1. Close IDE
  2. Locate folder where PhpStorm 2020.2 stores indexes/caches on your computer (see below)
  3. Delete that folder (as standard "Invalidate caches" does not help here)
  4. Launch IDE

Typical locations for caches folder for different OS:

  • Windows: %USERPROFILE%\AppData\Local\JetBrains\PhpStorm2020.2\caches
  • Linux: ~/.cache/JetBrains/PhpStorm2020.2/caches
  • macOS: ~/Library/Caches/JetBrains/PhpStorm2020.2/caches

https://youtrack.jetbrains.com/issue/WI-54626


I believe we should consider some things here. What version of PHP are you using. Not all version of PHP supports Exception and the namespaces does matter except you are using a dependency manager which may come configured with its namespace but if you are building from scratch, you may want to consider the namespace and the version PHP


If you are working with php below 7.1, Exception won't work because it does not implement the Throwable class. The only way for your exception to work is if you extend the Exception class.What I also do is to put a slash before the exception. Like throw new \InvalidArgumentException. Hopefully this works for you. Good luck

Tags:

Php

Phpstorm