1

I am curious as to why the following syntax is rejected by my PhpStorm editor:

enter image description here

PhpStorm version: 2016.1.2

7
  • 1
    Wrong (too low) PHP Language Level set up? Have you even tried hovering over the error to see the error description? It's also possible that your version does not support this syntax (it's an over 1 year old version) -- it will definitely work in latest version (considering the right language level was chosen, of course) Commented Aug 3, 2017 at 10:55
  • Error states: "Method should either have body or be abstract" Commented Aug 3, 2017 at 11:07
  • PHP Language level set to 7 Commented Aug 3, 2017 at 11:08
  • Saving some dosh to upgrade :) Commented Aug 3, 2017 at 11:09
  • 1
    And it would seem the error is being invoked by the '?' before User with message "Unexpected Identifier". Commented Aug 3, 2017 at 11:11

1 Answer 1

2
  1. Nullable parameters/return types (?User from your example) is a PHP 7.1 feature.
  2. PHP Language Level must be set to 7.1 in PhpStorm settings for this project (although right now it does not produce an error if language is set below 7.1 -- see WI-32136 ticket).
  3. Support for nullable types was added in PhpStorm 2016.2.2 (which is newer than your 2016.1.x)

Conclusion: upgrade your PhpStorm to the latest version (which is 2017.2.1 at this moment). At very least you need to have PhpStorm 2016.2.2 for this particular syntax to be supported 9not showing an error).

Sign up to request clarification or add additional context in comments.

1 Comment

That explains it. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.