Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106297 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2632 invoked from network); 25 Jul 2019 17:17:09 -0000 Received: from unknown (HELO mail-io1-f46.google.com) (209.85.166.46) by pb1.pair.com with SMTP; 25 Jul 2019 17:17:09 -0000 Received: by mail-io1-f46.google.com with SMTP id j6so22586183ioa.5 for ; Thu, 25 Jul 2019 07:40:49 -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=ysyMVrsCmBM/jACGp3w+c8TPwd8vHcTKZWE8bdial8k=; b=IbXlY/jBYjOweyPClPkqaqqWJmyefWaNB4jHavl4E725UCyR8ZjUCkpXejNsGP0S1h I7c/8NTFzjiEk6UFHpbONcLjgoaAclZFWIquVLjG7iEizwxmX9q22UF3dqg3MU9XONoS 4+BXUuC0M84jfMntfsX4FHNXSFoBNcCCsBVmWbwv++/1miHSmA/Xaw3dAri94f0Icr9u Fh7aYStwGmPBJaPFIoJUGyeGvJ6c9fSfvfbxZTykFFg8SZOdIKtnoGdDSRkCYFv1Ue6p V2Gv3wXRN+f8r23oHJFzdWw5SkrckkEYhrvp5gNevT4wc2F87bEe/YnR69vJdwfVaE55 wHuw== 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=ysyMVrsCmBM/jACGp3w+c8TPwd8vHcTKZWE8bdial8k=; b=Y2Yb941XWkzLqssPzGy1E8k5A7PoYA4iOGdsYTPTVtS799yuQNERmFMv7wlsAzLOcI Y6E+IDA7n4w0pqIygD58MXaGidJ2gvGnc9gYftYOUu1qZa8rg2utBCdYvUwManjk5JqI CAGyHwg7gy3exNOKrLsaOeQRdq4u/aVK6jO14AqSTMzS6hrjfZr2MeYe7RTSDmYQLV/X mRikYSOCNsp9RGGa7oNGB0NsQirBSsBhRIyfIfWY76tMmBacGOMNBnuQr3djGuZXGn58 t1UQt6YTZQWLaMRgqvoxukvtdTY4IFvWIdwRTNgYRUEzlnwM8gRBxKjRy8ENjmbhSDg5 v7Qw== X-Gm-Message-State: APjAAAVB/jPCLHJHq3XAQ6/8Rj6tueFMfpgG/buYpQKsFM/f9D/If4lz 9yFyHwfRZUuaXwaEgWVd+daHptV9ayXlXslXkXQP2NEB X-Google-Smtp-Source: APXvYqxaRSSD3iBEAXp4o7czpknLAYOZAsin/17D618ZqFeeY0kN2KVx8hfiFTmhE4DIbv+0gOeorS/FC324nYh7CIM= X-Received: by 2002:a5e:9304:: with SMTP id k4mr85044240iom.206.1564065648988; Thu, 25 Jul 2019 07:40:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 25 Jul 2019 15:40:37 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000069d79e058e826989" Subject: Re: [PHP-DEV] Re: [RFC] Explicit call-site send-by-ref syntax From: rowan.collins@gmail.com (Rowan Collins) --00000000000069d79e058e826989 Content-Type: text/plain; charset="UTF-8" On Thu, 25 Jul 2019 at 14:48, Nikita Popov wrote: > I think nowadays it is well known that by-reference passing is to be > avoided and I don't see it particularly commonly in user code. By-reference > passing is mainly used when it is needed to interact with existing > by-reference functions such as preg_match(). We can hardly switch these > functions to use out/inout if we require the corresponding keyword on the > call-site. > I guess the call-site syntax would still need to be opt-in for compatibility reasons, but we could definitely mark the parameters as "out" in internal functions, even if that was mainly a documentation / reflection change. That would stop people having to write `$matches = []; preg_match($foo, $bar, $matches);` to ensure that the output parameter is initialised. I have been annoyed by that more often than I've encountered a function where I wasn't sure if the parameter was by-reference or not. This proposal (in conjunction with the option to make it required) would > solve the main issues I have with the by-reference passing implementation > If this remains optional, I wouldn't have much appetite for using it, because the benefit feels very slight. The fact that it wouldn't always be mandatory makes the benefit even slighter, since you still couldn't look at foo($bar) and know whether it was by-reference without also knowing what declare options were in scope. > the out/inout approach is a refinement over that, but I'm not convinced > that it a worthwhile refinement relative to the language and engine > complexity it will introduce. > Would it really be that complex? The only real difference between "out" and "&" would be automatically setting the variable to null when it was passed to the function. Regards, -- Rowan Collins [IMSoP] --00000000000069d79e058e826989--