Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105943 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10043 invoked from network); 16 Jun 2019 01:38:57 -0000 Received: from unknown (HELO mail-pg1-f179.google.com) (209.85.215.179) by pb1.pair.com with SMTP; 16 Jun 2019 01:38:57 -0000 Received: by mail-pg1-f179.google.com with SMTP id 196so3648858pgc.6 for ; Sat, 15 Jun 2019 15:52:43 -0700 (PDT) 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:cc:content-transfer-encoding; bh=gIyWzC5JYDO296K8eXeebz+kNJIx5fVCUtQtIUbuMW4=; b=KSlnTfFWNkqqjdV4Mqhwoe9nVbVJMxAWp1DXSyRxUDxuhu1l6StPQRF2iVMEov8KMn N/7CFU5wDooi2dJPQxR+gAoGwnxntAqXlTn21cT3aWLY1OA7EwHEWhBVtZYgb4BLJ58b UxrMFmd6ogeXSiBfi2EbwrKchNhPi92jH58vC+Vykyz4kLy74FncQA7Y8jsoKJGA3X2q /c+YOULUMPm5cFU6fa+D43lzs+tDN2bjohTzTBoC08RZNddBF90IDCCEJQIFRPGxtEH8 CSYfmQdZ7ipSrNr3xfLYJw0sZEtcR2ihHpkP+WC6Oqjq6aE/74TQmF/MtVWNfd4gR+rt sBfQ== X-Gm-Message-State: APjAAAV2t7r215FQKNdollu9xC83OuskMTd6yJTWOE17yZ6k1Js/c0sI ZYxfmVUU+qAnMxutGoHSNGWxQmm/sP+8uEpXsUc= X-Google-Smtp-Source: APXvYqzJf0r8Eb+4yrg/RYo8E31eNfdmKnZMYP/6E6kN0syl8v/gMWZB0j0C/jK7vG4+TGru2JCLoybnj0l3/3nQrWs= X-Received: by 2002:a17:90a:8a91:: with SMTP id x17mr18286498pjn.95.1560639162483; Sat, 15 Jun 2019 15:52:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 16 Jun 2019 01:52:30 +0300 Message-ID: To: Wes Cc: Marco Pivetta , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV][RFC] Alternative "use" syntax for Closures From: kalle@php.net (Kalle Sommer Nielsen) 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. But > 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. --=20 regards, Kalle Sommer Nielsen kalle@php.net