Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101414 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24154 invoked from network); 24 Dec 2017 16:45:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Dec 2017 16:45:30 -0000 X-Host-Fingerprint: 95.145.9.240 unknown Received: from [95.145.9.240] ([95.145.9.240:23348] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/D1-21991-9A9DF3A5 for ; Sun, 24 Dec 2017 11:45:29 -0500 Message-ID: To: internals@lists.php.net References: Date: Sun, 24 Dec 2017 16:45:26 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 95.145.9.240 Subject: Re: [PHP-DEV] [RFC] Explicit call-site send-by-ref syntax From: ajf@ajf.me (Andrea Faulds) Hi Levi, Levi Morrison wrote: > On Wed, Dec 6, 2017 at 12:49 PM, Nikita Popov wrote: >> Hi internals, >> >> I'd like propose optional support for explicitly marking by-reference >> argument passing at the call-site, in addition to the declaration-site: >> >> https://wiki.php.net/rfc/explicit_send_by_ref >> >> In short, while currently we have >> >> function byRef(&$ref) {...} >> byRef($var); >> >> this proposal would also allow >> >> function byRef(&$ref) {...} >> byRef(&$var); >> >> so that the use of by-reference passing is obvious without having to >> consult the function declaration. > > I think we ought to commit to requiring the ampersand at the call site > some point in the future. As others have noted it provides little > benefit at the call site if it is not required. > > However, there is an area where this does provide value that others > have not yet mentioned or thought of: `callable` parameters. > > public function apply(callable $f) { > return $f(&$this->data); > } > > This requires the callable to accept the argument by reference, > something we cannot currently require. Of course this is rarely > needed; I am merely pointing out this feature is more than a syntactic > hint to humans. > > Based on the current discussion I would vote yes on this RFC, despite > the concerns raised by others. > Perhaps more useful is the inverse: in future, we could require that a callable *not* take a value by-reference unless the caller asks for it. That would prevent potential monkeying with the scope of the caller by the callee — if right now you do $f($this->data), you might forget that $f could take that parameter by reference and gain the ability to modify that variable indefinitely… Thanks -- Andrea Faulds https://ajf.me/