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
Status: Closed Package: PHP Language Specification
PHP Version: 7.1+ OS: Debian GNU/Linux 8
Private report: No CVE-ID:
 [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-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC