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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
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 Mar 29 10:01:28 2024 UTC