Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105131 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34512 invoked from network); 7 Apr 2019 15:37:40 -0000 Received: from unknown (HELO mail-wm1-f68.google.com) (209.85.128.68) by pb1.pair.com with SMTP; 7 Apr 2019 15:37:40 -0000 Received: by mail-wm1-f68.google.com with SMTP id z6so13143230wmi.0 for ; Sun, 07 Apr 2019 05:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=+rbdVsRHVdH7EK/y2n5tgPTMnVAn+k3P1gkxoA1Y+b8=; b=VhrkcYHL9wDNXTQerNuoNqBmKk8wpRepLIEm94llar3L/7kfmYj9ZB02tPcSd5zGBP s7FOH+U05eVcYKXaaXgtMK8dzCcMCNB9RawrPVjlOAuoy7VEpONYBBQkuaoEGAv0k7Vp ZbcGLkWYLSmROG7YASZ8ZFyAvaYqv4lvxkVbXhAYqial8XW4oBvOPFKZx7ZoUKcv4Jkw C1JtgF1McORksQkvW+7bFP6WUFHVDSwdseHB4lWNlsqmGVWMAv0QYQSQZ5Qc45jUn6z5 lfBBtI+MMVVS6HOQaDds6QycVZI+KSAA0adPpjNQG9VMYOweUTxeVqbohfj2HvbCCrP8 VCiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=+rbdVsRHVdH7EK/y2n5tgPTMnVAn+k3P1gkxoA1Y+b8=; b=BtZuQoqoTrglrERnGhru6mNaXtESUvWuTSGOMSEtIaPbqy+qgjMDyNcZuX4J7TjuZf wuhvLF9mv5kpOiauJMEmSiquwDNUWXcLtUYxudPGivlxcQuX0rFhvnGoY1VWCGS/kF8R HYNscuxbnR+i6yyLpD/66yuQFQSJTqcRj9Gq22B7EyZnxul9P7fW+87PyTsu6QY2nBC9 /2RCUFZ3P2jLthE2DJIAZ6XR+QEyMHbBWMrDC/xzpqzdHllqN61iQFVyXKt7WNGWvUxv WFpdKzxwAct2/ACMVkbGywxTfbY/hXYNon+4mj6ed6K5RGMR2NwUxpfm1I5imiXXKhyE brRg== X-Gm-Message-State: APjAAAXO6jbg6D1dwboOWzPC1Cj4vx1WLFRr/aHin0f5xnDdHKWXvgT8 amXMDhJ4o1YwW8jcYiVEPe6rMYH4 X-Google-Smtp-Source: APXvYqwJGC/2y7t+5tDZdHs3JXdop3DYLxFPOsL33DZX+w1NbZAT0drmV7kzOjBAtYVLA1745QycVw== X-Received: by 2002:a1c:39d7:: with SMTP id g206mr13104475wma.99.1554640442790; Sun, 07 Apr 2019 05:34:02 -0700 (PDT) Received: from [192.168.0.16] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id r30sm85679385wrr.46.2019.04.07.05.34.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Apr 2019 05:34:01 -0700 (PDT) To: Internals References: <00ab01d4ecfe$e0b03680$a210a380$@jhdxr.com> Message-ID: <831b949a-f2e5-635a-c83b-e936a9f34cc7@gmail.com> Date: Sun, 7 Apr 2019 13:33:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Parameter skipping From: rowan.collins@gmail.com (Rowan Collins) On 07/04/2019 11:53, Morgan Breden wrote: > >In order to use named parameters, somebody needs to have declared > what those names are, and made them a stable API. If they're > automatically supported on existing functions, the author might not > intend them to be used, or even realise they can, so not keep them > stable (I tend to think of parameter names as local, not contractual). > > Wouldn't using the name of the variable that is already used for its > function signature work perfectly fine for this? > This is how IDEs already hint for function call completion. Yes, that's what I meant by "automatically supported on existing functions". The problem I was highlighting is that right now, I can write this in version 1.0.0 of a library: function foo($id) {     $blobId = $id;     doSomething($blobId); } And change it to this in version 1.0.1, without violating SemVer: function foo($blobId) {     doSomething($blobId); } The name of the parameter is an implementation detail, not a contract. If named parameters are automatic, that suddenly becomes a breaking change, and either every library author recognises that and avoids such changes, or every library user has to check documentation to see if it's safe to use named parameters. Worse, as highlighted in the 2013 RFC, parameter names aren't checked when over-riding a method, like this: interface Fooable { public function foo(int $id); } class Blob implements Fooable { public function foo(int $blobId) { ... } } So either the first version of PHP to support named parameters would require library authors to change any such code, or again the library user has to check if it's safe to use named parameters. The alternative is to make named parameters opt-in on the part of the function author, using extra syntax in the function declaration. I think that's a better approach, but probably means an even longer wait until libraries introduce it. So realistically, even if named arguments were added right now, they couldn't reliably be used to skip over default parameters in existing functions. None of this is a problem with a simple "default" keyword, which would work reliably with all existing function signatures where a default is defined, and require no change in code or practice on the part of library authors, so can be introduced right now, and used straight away. Regards, -- Rowan Collins [IMSoP]