Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68681 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6486 invoked from network); 29 Aug 2013 12:02:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Aug 2013 12:02:45 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.46 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.46 mail-oa0-f46.google.com Received: from [209.85.219.46] ([209.85.219.46:45369] helo=mail-oa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/33-23883-2683F125 for ; Thu, 29 Aug 2013 08:02:43 -0400 Received: by mail-oa0-f46.google.com with SMTP id o20so398036oag.19 for ; Thu, 29 Aug 2013 05:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=UMEKl73XIus4CpZMrQHWrnMPF2EkfCevIcekE0E3bto=; b=pQ5lJrhXKPEsjqhwCwy/hR1Srt5q2kWrf5NTKq39llp4FryK55Gkrmfu0xG6V/J6kI zE24RLTGKkM8+vQRL/nUxI8pjepVS89Xq8xEZ0VfgTmdTIPZT/CztU/VEu8uV4zZb6cy fK/vY7MZNBskm/1ndvN9UpMT/sNJOcmUbbV9zqI/EO86fcLFOBkafUsZCcj/ow9XVZ2N qaAKZxAjgkYhLEjlGzoHK4JLPjkHGrN6oxMIgemTgzNAUZxTQ+GFy/+zwOFZnFphXK22 7hbosq6g+zs9oXc0a3NhJ7yMHrcXaHvtcwF6o6ODXfzRHlTD/RiU9nPNDoMbMEPV2C/h jzIQ== MIME-Version: 1.0 X-Received: by 10.182.214.98 with SMTP id nz2mr2241698obc.37.1377777760113; Thu, 29 Aug 2013 05:02:40 -0700 (PDT) Received: by 10.182.98.8 with HTTP; Thu, 29 Aug 2013 05:02:39 -0700 (PDT) In-Reply-To: <521E750F.6070800@sugarcrm.com> References: <521E750F.6070800@sugarcrm.com> Date: Thu, 29 Aug 2013 14:02:39 +0200 Message-ID: To: Stas Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=e89a8ff1cefef89c5a04e514e100 Subject: Re: [PHP-DEV] [RFC] Syntax for variadic functions From: nikita.ppv@gmail.com (Nikita Popov) --e89a8ff1cefef89c5a04e514e100 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Aug 29, 2013 at 12:09 AM, Stas Malyshev wrote: > Hi! > > I like the idea, the concept of capturing "rest of args" is pretty > common. But couldn't we in addition have func_get_args() be able to > receive an int argument that would produce "the rest" in an easier way > for those that prefer func_ger_args()? > I would do that if this RFC doesn't pass, but I don't see much point doing both things (syntax + extra arg). Are there any particular scenarios where using func_get_args() would be preferable? > For prototype checks, this: > > public function query($query, ...$params); > public function query($query, $param = null, ...$params); > > Should be compatible. It already is. Only requirement is that the typehint/by-ref-mode of $param=null is compatible with the typehint/by-ref-mode of ...$params :) > Same with: > > public function query($query, ...$params); > public function query($query); > > functions should be able to ignore some arguments, especially ones that > are optional anyway. I also think this: > > public function query($query, ...$params) > public function query(...$params) > > should be legal too. > I would like to stay consistent with the normal PHP behavior here. PHP currently doesn't allow leaving off (required or optional) parameters. I created a separate thread regarding that issue: http://markmail.org/message/ejgmqjnjnbmfnuzv If we decide to allow having less parameters there, then I'll follow suit here as well. > I think it should also be explicitly specified what $params is if there > is no arguments - null? false? array()? I'd probably prefer array as it > makes it easy to do something like: > > public __construct(...$params) { > foreach($params as $k => $v) { $this->$k = $v; } > } > > but in any way it should be specified. > Now specified in https://wiki.php.net/rfc/variadics#population_of_variadic_parameter: The default is an empty array. Thanks for the comments, Nikita --e89a8ff1cefef89c5a04e514e100--