Home » Php » PhpStorm not recognising core PHP

PhpStorm not recognising core PHP

Posted by: admin July 12, 2020 Leave a comment

Questions:

PhpStorm isn’t recognising core PHP. For example, it’s not recognising Exception, with the tooltip saying “Undefined class ‘Exception'”.

I’ve tried invalidating the cache to no avail. I’ve checked a colleague’s installation and they appear to have no issues, and after Ctrl+Clicking on their Exception class, it links correctly to Core_c.php, which isn’t the case for me. It seems like my PhpStorm isn’t picking up the PHP plugin / library, and I have no idea why.

I’ve tried reinstalling PhpStorm to the latest version, upgrading all of my packages. I’ve even made sure that the php.jar plugin is actually there, and it is:

/opt/phpstorm/plugins/php/lib/php.jar

And the PHP plugin is enabled in PhpStorm.

Another problem I have with PhpStorm is that it isn’t suggesting function names whenever I type them. Help would be appreciated, and I can provide additional information if needed.

How to&Answers:

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

Answer:

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