How change the position PHP Class imports are placed?

Answered

Hi,

Whenever I import a class in a PHP class the import gets placed right under the namespace.
This is not where it should be, PHPStorm even sees this as an error.

Screenshot: https://imgur.com/a/BUdkH

Is there any way to change the position these imports get placed?

The imports are generated by pressing ALT+ENTER and pressing import (as you do).

Thanks,

 

0
2 comments

Hi there,

No concrete idea why you see an error there -- AFAIK that's a valid code. Possibly it's coming from CodeSniffer integration .. or some parsing glitch that got "sticky" (for later the cut & paste may help). Would be good to see what IDE tells about it -- what error it reports (full message).

In any case: please check your Code Style for PHP -- "Settings/Preferences | Editor | Code Style | PHP --> Blank Lines tab" -- place "1" in appropriate places.

P.S. Does "Code | Reformat Code" adds such empty lines if you run it on the whole file (if you have "1" in those appropriate fields for PHP Code Style)?

2
Avatar
Permanently deleted user

First of all Thanks for your fix, it worked perfectly!.

The error is: The 'use' keyword must be declared in the outermost scope of a file (the global scope) or inside the namespace declaration

Weird error indeed and, using Code | Reformat Code does not change anything when executed on the whole file

Anyway, thank you very much for the solution!

0

Please sign in to leave a comment.