Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106323 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50980 invoked from network); 29 Jul 2019 18:10:06 -0000 Received: from unknown (HELO mail-io1-f47.google.com) (209.85.166.47) by pb1.pair.com with SMTP; 29 Jul 2019 18:10:06 -0000 Received: by mail-io1-f47.google.com with SMTP id e20so90545132iob.9 for ; Mon, 29 Jul 2019 08:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=hd2hRS1n7cF4D29DYpWIQFkb6SuzPvB7oCb1Jcgf5Ts=; b=mBmw/8NHQ5tGksyDH9KfIirHzqJwYh1EkpC0xkM31JgkvC17S0vZQzMRL12TqdXNH7 tMh+rVxLu6dfHsfs1KtEd4G8IPxn5GMDrrPsh+mPpwjBvUlorMYuXnyNtYFj+1nUOVJP TT+vY2e8wZutDFCIYl2w21gJcRKERQY8NrTI3PcQwiLk0HJowJOdLgIvtxfDMH+whGXT SkWMaFgcgmva1RV4GCfjy5lhk+OLbdLil7us1tPlXs++SxZntVthOs0u7IAjk+SbWSHN BhLrti1M8glkgO6ONksPHrvRAS0EVD6zIscn5TWySCkHkN4nz0elZDfpxTlC2RisTVwy LnBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=hd2hRS1n7cF4D29DYpWIQFkb6SuzPvB7oCb1Jcgf5Ts=; b=ta6bMoU671A4FqqeJJNbAsLrQXPy4CnQdD4hNu4q3aioj0lWWBcP4oFFr1PoatXV18 pRU6Tkli/ESPSZdIjge9QUco/J0YcH0Q/CU8iOk85CkRBm+5vPLg8MWVs9bBZxNgD5EK mNiQuEBqs1l+tK2o9DXQ5f/cBWbTJyT4bgc7Fw1QJzvWFrRV9njHCL/KXzxH5Jt8EDiF Gv3fUyzFbXGvL0ItkB1eG2kcbLJAov29L5KcuyRCKo6KardL1ioY0R4Sj75rUZb/A+wS gjwwoTNJ3cqqFWtN+qbBFDvCW8AvYwhhaLWUP0LtjXEAJR2LL2iIuvMboPUVUwaxDX23 bTaQ== X-Gm-Message-State: APjAAAVMA+PDQhqjYlarZIqY4+cYuQ5HYC2gvmxDIjMA3OuasD2wEfWa eXidIlIQ9Gs6ZMjxEnA7znUu2z2wd9mNXUgiXGqoQlKi X-Google-Smtp-Source: APXvYqy1+eGDPLNnfvanl2q1UeoNp+mCwAdLsUX0auWxelEDF8bE6rt802ohzxC/dJkAynUZrVMrZ1Jd3b8zOuemgjo= X-Received: by 2002:a5e:9304:: with SMTP id k4mr16164379iom.206.1564414486408; Mon, 29 Jul 2019 08:34:46 -0700 (PDT) MIME-Version: 1.0 References: <9aba78c9-f04d-45b8-6c34-ad1c2472ef76@gmail.com> <75d04139-b944-f204-f988-959fa6f3e305@gmail.com> <8CD3B476-ABF9-4DB7-96D3-217064023854@gmail.com> In-Reply-To: Date: Mon, 29 Jul 2019 16:34:35 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000be7509058ed3a1fa" Subject: Re: [PHP-DEV] [RFC] Explicit call-site send-by-ref syntax From: rowan.collins@gmail.com (Rowan Collins) --000000000000be7509058ed3a1fa Content-Type: text/plain; charset="UTF-8" On Mon, 29 Jul 2019 at 15:41, Nikita Popov wrote: > This proposal (at least combined with a declare that enforces use of > call-site annotations) addresses that concern. out/inout parameters do not > address this concern, because they are an mechanism that would be used *in > addition* to normal by-ref passing, and as such not address any problems it > has. > > The only way I see in which out/inout would actually address the concern > of this proposal is if out/inout were used instead of & at the call-site, > but the parameter were still a normal reference. I don't think that's a > good idea because it breaks symmetry between arguments and parameters, and > also squanders any future potential to use out/inout as a way to reduce > reference-use in this context. > > Does that make sense, Rowan? To put is more compactly, what I want is an > eventual state where given $fn($a) I have a guarantee that $a is not going > to be magically modified, without having to perform any global reasoning > about what $fn may refer to. If an alternative proposal does not result in > this eventual state, then it is not an alternative to this proposal (but > possibly still a valuable addition in itself). > It does, yes. I guess what I had in mind was that *in the long-term*, out/inout parameters would replace & parameters, so rather than declare(require_reference_at_call_site=1) you would have declare(disable_reference_parameters=1). Whether or not it's a direct alternative to this proposal, I also worry that out/inout parameters are somewhat mutually exclusive with it: the more effort is spent on making reference parameters "better", the less appetite there will be for replacing them altogether. I agree the behaviour of type annotations would need deciding, but arguably that should have been true for by-reference parameters; it's somewhat bizarre that you can write "function foo(SomeClass &$x) { $x=42; }" The solution would probably be to reuse the "typed references" from the typed property implementation. > Bob has brought up another interesting issue: This proposal currently does > not address the case of foo(...$a), where references into $a may be added > if foo() has by-reference parameters. The suggestion was to use foo(&...$a) > -- however in this case only to *allow* the use of references, not require > it (some args may be by-val while others may be by-ref). > There's probably a bit of a rabbit-hole if the mission is "make references explicit". An array containing a reference can be passed by value, for instance, so $fn($a) might not technically modify $a, but still modify elements inside it. So it seems like we come back to "this is kind of useful information but may not actually offer a hard guarantee". Regards, -- Rowan Collins [IMSoP] --000000000000be7509058ed3a1fa--