Bug #68625 [Opn->Csd]: By-ref parameters with array/callable typehints should be permitted

[email protected]
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=68625&edit=1

 ID:                 68625
 Updated by:         [email protected]
 Reported by:        ajf at ajf dot me
 Summary:            By-ref parameters with array/callable typehints
                     should be permitted
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PHP Language Specification
 PHP Version:        5.6.4
-Assigned To:        
+Assigned To:        stas
 Block user comment: N
 Private report:     N

 New Comment:

Looks like this is already fixed.


Previous Comments:
------------------------------------------------------------------------
[2014-12-28 18:10:50] [email protected]

I was wondering if it might be broken in HHVM or something, but this works in PHP 5.6 and HHVM:

http://3v4l.org/cs5LO

Interestingly, callable-by-reference would appear to be broken in current PHP 7 master, if 3v4l is up-to-date. I'm not sure if it makes any sense to allow callable by-reference, but this seems like a regression.

------------------------------------------------------------------------
[2014-12-28 17:29:28] [email protected]

Let's turn it around: why ban it? It definitely gets interesting if you pass in a callable and get back ... I dunno what ... but why not?

------------------------------------------------------------------------
[2014-12-28 17:21:56] [email protected]

I'm not sure that taking a callable by reference has any kind of logical sense to it. Taking arrays by reference is definitely valid, though.

------------------------------------------------------------------------
[2014-12-19 03:11:53] ajf at ajf dot me

Description:
------------
The language spec states this in spec/13-functions.md:

  *parameter-declaration* must not contain `&` if *type-hint* is `array` or
`callable`.

Yet PHP allows this:

  $ php -r 'function a(array &$foo) {} $a = []; a($a);'
  $ php -r 'function a(callable &$foo) {} $a = "strlen"; a($a);'
  $

Why, then, is it prohibited in the spec?



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68625&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.