4

I installed the last version (Oxygen) of Eclipse for PHP. But now there are lots of error annotations that I think they shouldn't be.

Almost all of them have to do with Exception:

throw new Exception('Exception message');

The annotation message in the popup hint is like so: Exception cannot be resolved to a type And the hint offers me some quick fixes, which are using the Exception class declared in libraries imported with Composer.

Why is that? As far as I know, Exception is still an internal PHP class (no need to import it). I know I should be using more specific Exception classes, but for now, Exception works for me. And it shouldn't be marked as an error in Eclipse. Prior versions didn't detect this as an error. Furthermore the application runs without any problem.

Is this a bug? Otherwise, how do I disable this type of error annotation?

EDIT:

Another annoying issue happening is that the code assistant is not displaying any php internal function. Only functions, classes and methods declared in my app or in imported libraries. For instance, if I type:

str

the code assistant displays classes from Doctrine, Geocoder, etc, and imported functions like "strip_quotes", but nothing about strstr, str_pad, strpos, etc

luis.ap.uyen
  • 1,314
  • 1
  • 11
  • 29

1 Answers1

2

Did you forgot about namespaces and PSR-4?

throw new \Exception('Exception message');

So when you are using a class which must be autoloaded, you must declare it via use or call it with full path (with namespace).

If you don`t want to write correct code and this message is annoying you, then I'm pretty sure that you can turn off this message via Eclipse configuration.

Neodan
  • 5,154
  • 2
  • 27
  • 38
  • I know about PSR-4 and namespaces. In most cases, the Exception is being used in the root namespace, so there's no need to prepend the backslash. In case I'm using the Exception class in other namespaces, I declare it with **use \Exception** first. However, no matter whether I use backslashes or not, Eclipse keeps marking Exception as if it cannot be resolved as a type. It's not happening with other classes. – luis.ap.uyen Aug 11 '17 at 07:34
  • Maybe it is the Eclipse bug? – Neodan Aug 11 '17 at 07:39
  • 1
    Not sure. Hence my question – luis.ap.uyen Aug 11 '17 at 07:46
  • It's very strange, everything is working correctly for me :| ```Eclipse for PHP Developers Version: Oxygen Release (4.7.0) Build id: 20170620-1800``` ```openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~15.10.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)``` – Neodan Aug 11 '17 at 08:18
  • This is my version: Eclipse Platform Version: Oxygen (4.7) Build id: X20170706-0009 – luis.ap.uyen Aug 14 '17 at 13:32