php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ajf at ajf dot me
New email:
PHP Version: OS:

 

 [2014-12-19 03:11 UTC] 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?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-28 17:21 UTC] levim@php.net
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] chx@php.net
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] ajf@php.net
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.
 [2015-06-28 21:03 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2015-06-28 21:03 UTC] stas@php.net
Looks like this is already fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC