Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68950 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43877 invoked from network); 7 Sep 2013 16:55:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2013 16:55:21 -0000 Authentication-Results: pb1.pair.com header.from=leverton@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=leverton@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.180 as permitted sender) X-PHP-List-Original-Sender: leverton@gmail.com X-Host-Fingerprint: 209.85.214.180 mail-ob0-f180.google.com Received: from [209.85.214.180] ([209.85.214.180:39496] helo=mail-ob0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/EC-00660-77A5B225 for ; Sat, 07 Sep 2013 12:55:21 -0400 Received: by mail-ob0-f180.google.com with SMTP id v19so4538692obq.39 for ; Sat, 07 Sep 2013 09:55:17 -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=w0XSUs61GTxoW/Xp2kL8O7F08l94xewLgo63+94pHLk=; b=qlGvR78xNxCgQksq//VEWmtXsRJZ7sxdNUXvtd3ML59ESlsz/z7RKEEnzZ6uD0Jo9H x+FwoF9DMJEf+7kXdTY1awfxJQtQf+oht+HgIBBmWjpKdFYtGFun6GjbnHx19GFv1sm3 2rC/qZLUzvYbBwQ9vEONw3GhwGV6JRuNoK4nc5WAtGnlrMXADxZoEZnEauu+al1mCy2j N1zlVHE0yLISBuMont6EH66ElOSzSSJuoR0VZgLBQ2m+J6OyHaN5kym6V4HaVE6AwOzu fM+hot7nzo8NuDYysn2rp/qSwwj/TugMzE095NBnIbFKmOjF51nlYaN37tnxDz2csByv 5bLg== MIME-Version: 1.0 X-Received: by 10.182.142.106 with SMTP id rv10mr5886380obb.51.1378572917059; Sat, 07 Sep 2013 09:55:17 -0700 (PDT) Received: by 10.182.133.34 with HTTP; Sat, 7 Sep 2013 09:55:16 -0700 (PDT) In-Reply-To: <522AFA6A.8010501@mjburgess.co.uk> References: <522AFA6A.8010501@mjburgess.co.uk> Date: Sat, 7 Sep 2013 11:55:16 -0500 Message-ID: To: Michael John Burgess Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Named parameters From: leverton@gmail.com (Matthew Leverton) On Sat, Sep 7, 2013 at 5:05 AM, Michael John Burgess wrote: > The position of parameters and the name of the function must already be > maintained... I dont see why appropriately naming variables is such a > burden. > I wouldn't necessarily make this objection if this were a day-1 feature. But it does bother me somewhat that all of a sudden code retro-actively starts supporting named parameters. The OCD in me shudders to think about now having to parse through people's code like: substr('length' => 1, 'string' => 'Hello World'); Now I see the function, and I have to see how they ordered their parameters. Why was 'start' omitted... is this a warning due to using NULL as an int.. did the person mean 'start', etc? It's just one example, but I know that this sort of code will start cropping up everywhere. So that's why I call this a nuisance. It just seems like a very marginal gain for lots of potential headaches. But I don't mean to make a mountain out of a molehill. After giving it some thought, I'd like some consideration to be given to providing an explicit syntax in the RFC at least so people consider all alternatives. I just don't think that giving people the ability to call a function with two well ordered parameters by using named parameters is worth causing all future code to diverge into two drastically different calling styles. My strong preference would be a syntax that separates the two types of parameters, such as the following: function func($a, $b, ...$params, [$c = 'foo', $d = 'bar']) { } func($a, $b, $extra, 'd' => 'override'); Here $a and $b are not named parameters and must be present. Extra positional parameters are sent to $params. The parameters enclosed in square brackets must be passed in by name as the last parameters, but can be omitted. I don't like the $ on the named parameter when calling because it implies that this works: $d = 'c'; func($a, $b, $extra, $d => 'override'); Now is 'c' overridden or 'd'? So I'll give this issue a rest unless somebody wants to further discuss what the concrete syntax might look like. -- Matthew Leverton