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

From: Date: Sun, 28 Jun 2015 21:03:41 +0000
Subject: Bug #68625 [Opn->Csd]: By-ref parameters with array/callable typehints should be permitted
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-813@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68625&edit=1 ID: 68625 Updated by: stas@php.net 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] 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. ------------------------------------------------------------------------ [2014-12-28 17:29:28] 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 17:21:56] 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-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

« previous php.standards (#813) next »