Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76620 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66572 invoked from network); 17 Aug 2014 21:59:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2014 21:59:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.245 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.245 imap11-3.ox.privateemail.com Received: from [198.187.29.245] ([198.187.29.245:56267] helo=imap11-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/B5-28428-1B521F35 for ; Sun, 17 Aug 2014 17:59:13 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 206428800DA; Sun, 17 Aug 2014 17:59:10 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id dTdrDGXSuHY2; Sun, 17 Aug 2014 17:59:09 -0400 (EDT) Received: from [192.168.0.2] (05439dda.skybroadband.com [5.67.157.218]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id A0C408800CB; Sun, 17 Aug 2014 17:59:08 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: Date: Sun, 17 Aug 2014 22:59:05 +0100 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <38FC0B11-5E15-43E9-8467-347359970D46@ajf.me> References: <235C617B-25E1-4185-A784-38EF1D7BFFDC@ajf.me> To: Levi Morrison , Stas Malyshev X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [VOTE][RFC] Closure::call() From: ajf@ajf.me (Andrea Faulds) On 17 Aug 2014, at 22:36, Levi Morrison wrote: > I have a small clarification question on the RFC: you are adding > another parameter to bindTo which defaults to false, but I didn't > quite understand the reasoning. Can you try explaining that to me in a > different way? I=92ll give it a go. Closures have a bound object and a scope. The bound object is whatever = $this will be set to when that closure is called. The scope is the class = whose private variables can be seen by a closure. ->call() will call the closure and use its existing scope but the bound = object will be what is passed as its first parameter. ->call() doesn=92t = permit calling with a different scope. This presents a conundrum, however, if you want to use ->call() with a = closure and you want to have a scope. Currently, ::bind() and ->bindTo() = only permit two types of closures with scopes: those that are static = (can=92t have $this bound) and those that have an object bound. This = means to create a closure with a scope that you can then use with = ->call(), you=92d have to make one with a dummy object already bound. In = most cases you can do this, but there are a few you can=92t, and it=92s = weird to have to bind an object when we=92re not going to use it anyway = as ->call() is going to override it. For this reason, a third parameter is added to ::bind() and ->bindTo() = which makes it produce an unbound, scoped closure rather than a static = scoped closure if we don=92t pass an object to be bound and we specify a = scope. The need for the third parameter is really just = backwards-compatibility. At the moment, if you pass NULL for the object = to bind to and pass a class name for the scope, it=92ll make a static = closure. We could change this and make it produce an unbound closure and = add some other mechanism to obtain a static closure, but that would = break backwards-compatibility. For this reason, we instead add a third = parameter to say, yes, we do want an unbound closure. The same thing is = done internally too, with zend_create_closure_ex. On 17 Aug 2014, at 22:55, Stas Malyshev wrote: > Hi! >=20 >> I have a small clarification question on the RFC: you are adding >> another parameter to bindTo which defaults to false, but I didn't >> quite understand the reasoning. Can you try explaining that to me in = a >> different way? >=20 > Interestingly enough, the RFC doesn't even mention this change. It does, but maybe you missed it. Under the Proposal section: > To solve this, we relax the current invariant of scoped closures = having to be bound, and add a new parameter to bind(To) to produce an = unbound, scoped closure, like so: -- Andrea Faulds http://ajf.me/