Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86755 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48116 invoked from network); 19 Jun 2015 00:34:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jun 2015 00:34:00 -0000 X-Host-Fingerprint: 68.118.157.39 68-118-157-39.dhcp.mdsn.wi.charter.com Received: from [68.118.157.39] ([68.118.157.39:11235] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/20-45584-77363855 for ; Thu, 18 Jun 2015 20:33:59 -0400 Message-ID: <28.20.45584.77363855@pb1.pair.com> To: internals@lists.php.net Date: Thu, 18 Jun 2015 19:33:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.118.157.39 Subject: Re: Output, parameter From: me@stephencoakley.com (Stephen Coakley) On 06/18/2015 11:12 AM, Dominic Grostate wrote: > A feature I'd quite like to see is something similar to C# out arguments. > Which is an argument provided empty to a function (or with a value to be > ignored) that the function must write to before returning. > > Normally this wouldn't be necessary since you can do this anyway by passing > by reference, however I would like to make the same case for it that was > made for return types. > > A possible syntax to differ from C# might be: > > function read(string ^$bytes, int length): int > { > > } > > The arrow indicating that a value will be written to the argument. > > Another case for this is the fact it is unfeasible to provide a type hint > for reference arguments because if the provided var is null or newly > created it will throw an error. > > Using type hints on outputs will both validate that the populating value is > of the correct type, as well as provide popular IDEs a hint to what the > type has changed to. > > Thanks, > Dominic I don't see this being useful enough for adding a new syntax. I always thought that "out" params in C-family languages was a hack and should be avoided if possible. Newer C++ libraries tend to return tuples instead, don't they? Most of the time people just return an array of values in PHP code I've seen.