-1

It's almost impossible for me to search for an answer to this as I don't know what this syntax is called.

I have a server running a relatively old version of PHP (5.5.38) and I'm getting parse errors when I run a file that has the following:

public function foo(): array
{

...specifically the : array suffix.

Can anyone tell me what this syntax is called (so I can research further) and which PHP version introduced it?

Mitya
  • 30,438
  • 7
  • 46
  • 79
  • Well I've seen these before function arguments, but never after the arguments list. New to me. – Mitya Dec 20 '18 at 13:31
  • 2
    http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration – Ismael Miguel Dec 20 '18 at 13:31
  • https://stackoverflow.com/q/40346754/6309457 – Devsi Odedra Dec 20 '18 at 13:32
  • Thank you, all. To downvoter - I'm not sure what you would suggest I should have done. I had no idea what it was called, which makes it rather tricky to search. To closer - it's very clear what I'm asking. I will mark the question as duplicate (to the one @DevsiOdedra linked to.) – Mitya Dec 20 '18 at 13:32
  • Well, search for : after functions and you'll find a lot of informations about the : ;) – Mr. Jo Jun 12 '19 at 20:32

1 Answers1

5

This was added in PHP 7, they're called return type declarations.

http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration

Oli
  • 2,343
  • 1
  • 22
  • 35