1

I have the following code:

class PairGalleryController extends Controller
{
    /**
     * @Route("/PairGalleryIndex")
     */
    public function IndexAction()?    
    {
        $output = "";    
    }
}

... and yet I see an error in my IDE saying that the method "should either have body or be abstract."

I'm sure I'm overlooking a simple solution. What am I missing that is causing this problem?

====

Edit: Interestingly, this code refuses to be formatted in the preview as code when I indent it on the StackOverflow editing form. So maybe there's an invisible character that's causing parsing problems in some way. That's my guess, anyhow. I would love to hear others' ideas.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

2 Answers2

3

Specific Answer to your question

The code I copied from your question indeed contains invisible characters:

<u+2028>, unicode character 'LINE SEPARATOR':

class PairGalleryController extends Controller
{
    /**
    * @Route("/PairGalleryIndex")
    */
    public function IndexAction()<u+2028>
    {
        $output = "";<u+2028>
    }
}

Try removing these characters.

General Answer

Since we have found out that the problem were invisible characters in the range of 'line separator' or 'zero width space', you can find possibilities to display whitespaces here:

  1. phpStorm: Zero Width Characters locator or: Settings -> Editor -> General -> Appearance -> Show whitespaces [source]
  2. TextMate: View -> Show Invisible Characters
  3. SublimeText: in user settings: "draw_white_space": "all" [source]

NOTE: please feel free to update and extend this list

Barthy
  • 3,151
  • 1
  • 25
  • 42
0

Change the "Language" to PHP 7.1. You are set to too low of a version. The nullable IndexAction()? is a feature starting in PHP 7.1.

BA_Webimax
  • 2,714
  • 1
  • 13
  • 15