php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71082 Documentation is unclear on the other of use clause and return type declaration
Submitted: 2015-12-10 15:59 UTC Modified: 2021-09-13 15:22 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: lists dot ban at herbesfolles dot org Assigned: levim (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.0.0 OS:
Private report: No CVE-ID: None
 [2015-12-10 15:59 UTC] lists dot ban at herbesfolles dot org
Description:
------------
---
From manual page: http://www.php.net/functions.anonymous
---

Syntax for mixing `use` Closure clause with return type declaration doesn't seem to be documented anywhere.  It's then unclear whether the `use` clause should come before (where PHP7 actually wants it) or after (where HHVM wants it) the return type hint.

PHP7:
    $closure = function (string $str) use (&$something) : int {}

HHVM:
    $closure = function (string $str) : int use (&$something) {}

As this not only isn't obvious, but also is inconsistent with what HHVM supports for some time, it seems very useful to me to document this clearly.

Test script:
---------------
<?php

$something = 42;
$closure = function (string $str) use (&$something) : int {
	return strlen($str) + $something;
};


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-19 04:19 UTC] levim@php.net
-Assigned To: +Assigned To: levim
 [2021-09-13 15:22 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC