|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68625 By-ref parameters with array/callable typehints should be permitted
Submitted: 2014-12-19 03:11 UTC Modified: 2015-06-28 21:03 UTC
From: ajf at ajf dot me Assigned: stas (profile)
Status: Closed Package: PHP Language Specification
PHP Version: 5.6.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ajf at ajf dot me
New email:
PHP Version: OS:


 [2014-12-19 03:11 UTC] ajf at ajf dot me
The language spec states this in spec/

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

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?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-28 17:21 UTC]
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-28 17:29 UTC]
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 18:10 UTC]
I was wondering if it might be broken in HHVM or something, but this works in PHP 5.6 and HHVM:

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.
 [2015-06-28 21:03 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2015-06-28 21:03 UTC]
Looks like this is already fixed.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 04:01:27 2024 UTC