Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105944 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15472 invoked from network); 16 Jun 2019 02:06:35 -0000 Received: from unknown (HELO mail-pg1-f180.google.com) (209.85.215.180) by pb1.pair.com with SMTP; 16 Jun 2019 02:06:35 -0000 Received: by mail-pg1-f180.google.com with SMTP id v9so3644166pgr.13 for ; Sat, 15 Jun 2019 16:20:20 -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=JtoNiQf8u0auW/pkcbjCPXUZKKj5omtQYmJY4MKcDNA=; b=n1dxScDXRnBcpIbltWjcEpnODIYLOJCHHIy4LbehBLkpI6T2t0Lqg0jVU1QSrkZjfK P+Sf8su3rgBbFK38PY4GrxW650y3TNskJ4EMBdykmxd1Pi7e7oJMu5hy4YGcIq9xFbby HhkrOJ3OihHipdPThiJBgkc9esQJcmUcUseMKdJhVAPhzmfbms/W5pA3JkX9rbSQ+ir9 WXaCKc4AOp0Ab7gXTB4UtDYpepPJjozH67CAAl9rbTS0CyQcrA8hgg5HSmfMQNxpataC 6RrnQx0gRqi6LdM6d4uf7m2s8q35P44OrcRK/elOeCw8NO3GCH7to4UgwkiPE43CGYWI ppng== 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=JtoNiQf8u0auW/pkcbjCPXUZKKj5omtQYmJY4MKcDNA=; b=k8MfM05Y9tJY4anKUORI5EW39y3zDSNUnQBnX0LA6T/4j4COa9Mqige/gTW3jobOTX Wof+KecMTlbxRiTStLHC/fpDF7pFH8WakcTnN3D9GU8GSq5K4vYxgwBqz4e2Od4rYLrP GsAKbMW+twnqSQDbHvQQMLWO8Nev4dM8Poo7uiVx4g8hxwWho2/RLs/UQmBNTnQNNr6W eE4UxRJWoyHEewytMF3DDD4fJ5DmCekXn5y5JoukVoBPPyehGpO+UcmOstYrZQI9A6rB KZW2J30xFmCo/IJqK+1dVFAc+uHWdFDEWbTaatc0FsVLTjQvzKRZyk4ishANfK1mZ5IC sYtw== X-Gm-Message-State: APjAAAWRIoUHyc8Yaf7LkcZyBegWgkLAlfaUHSNQHqGo+hCxe3AOHhxR XX3N4vXasuC2OtVKO784In/ZYNDErOXf+xFH24U5lP93 X-Google-Smtp-Source: APXvYqzM7VlMMec4Ec/0/GnymMsWo62BZ7eS3GUTubHOtJXRlpfF0PfBH7HOy6PFqxO2EFhDm2oMcaqvlKvtrvgOkUY= X-Received: by 2002:a17:90a:2247:: with SMTP id c65mr17646500pje.24.1560640818905; Sat, 15 Jun 2019 16:20:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 15 Jun 2019 16:20:08 -0700 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000a204c8058b6501bd" Subject: Re: [PHP-DEV][RFC] Alternative "use" syntax for Closures From: mo.mu.wss@gmail.com ("M. W. Moe") --000000000000a204c8058b6501bd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, mostly, your argument in your rfc, is all about not finding a good syntax; hence your have a terrible coding style and you want to change the language for that. ``` $fn =3D function ( T1 $arg1_ , T1 $arg2_ , T1 $arg3_ , T1 $arg4_ , T1 $arg5_ , T1 $arg6_ ) use ($var1, &$var2, &$var3, &$var4): T2 { // If you want to import more scope vars your code is // smelly, should think about writing something else. return new T2; }; ``` On Sat, Jun 15, 2019 at 3:52 PM Kalle Sommer Nielsen wrote: > Hi > > Den s=C3=B8n. 16. jun. 2019 kl. 01.37 skrev Wes : > > > > Hi Kalle, I realize it's going to be a bit odd when binding by value. B= ut > > it's not that hard to grasp. > > > > ``` > > $a =3D 123; > > $closure =3D function(){ > > use $a; > > echo $a; // 123 > > }; > > $a =3D 345; > > ``` > > Take this example: > > function get_closure() { > $a =3D 123; > > return function() { > use $a; > echo $a; > }; > } > > get_closure()(); > > $a is not available at this time because the scope of which $a exists > in is destroyed at this point, which is why it exists as apart of the > prototype like I mentioned and therefore it can be captured. > > Your idea means we need to scan the body of the declared closure for > use statements to perform the binding at this stage, adding extra > specialized steps in the executor for only makes me question the > motive for this again, and if the motive is that "I'm passing an > excessive amount of values to a closure", then I think you are forcing > a technique that isn't mean for this to do it anyway. Another thing to > take into consideration here is the performance impact that it can > potentially have. > > Whether or not its at the top of the body or separated in multiple > statements or all over the body still means we need to check if the > body contains such a statement and do the right computations for it, I > still don't think the argument presented in the RFC justifies this > potential cost, and would like to see a demo implementation and impact > it would have first. > > > -- > regards, > > Kalle Sommer Nielsen > kalle@php.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --000000000000a204c8058b6501bd--