php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 - 22 = ?
Subscribe to this entry?

 
 [2015-06-23 19:04 UTC] tim dot bezhashvyly at gmail dot com
Description:
------------
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 ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

Sadly this was not covered by the Return Types RFC: https://wiki.php.net/rfc/return_types

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] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2015-06-23 19:32 UTC] cmb@php.net
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] <https://wiki.php.net/rfc/arrayof>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 05:01:29 2024 UTC