|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69914 Not possible to specify array type as a return type
Submitted: 2015-06-23 19:04 UTC Modified: 2015-06-23 19:32 UTC
From: tim dot bezhashvyly at gmail dot com Assigned: kalle (profile)
Status: Closed Package: PHP Language Specification
PHP Version: 7.1+ OS: Debian GNU/Linux 8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tim dot bezhashvyly at gmail dot com
New email:
PHP Version: OS:


 [2015-06-23 19:04 UTC] tim dot bezhashvyly at gmail dot com
Specifying specific array type as a return type of a method/function produces a syntax error.

Test script:
function foo(): string[]
    return ['bar'];

Actual result:
Parse error: syntax error, unexpected '[', expecting ';' or '{' in ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-23 19:09 UTC]
-Status: Open +Status: Not a bug
 [2015-06-23 19:09 UTC]
There is no such thing as a typed array.
 [2015-06-23 19:11 UTC]
-Status: Not a bug +Status: Open -PHP Version: 7.0.0alpha1 +PHP Version: 7.1+
 [2015-06-23 19:11 UTC]
Hi Tim!

Sadly this was not covered by the Return Types RFC:

It is too late to cover for 7.0 now, hence the updated 'version' field in this report. I suggest you mail the internals mailing list for some debate or create an RFC for this once 7.0 have been released and developments began to focus 7.1
 [2015-06-23 19:11 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2015-06-23 19:32 UTC]
There is already the closely related "Array Of" RFC[1], which has
been declined (see the link to the mailing discussion at the
bottom of the page for details).

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC