Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76425 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17599 invoked from network); 11 Aug 2014 11:25:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2014 11:25:46 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:48919] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/11-11469-938A8E35 for ; Mon, 11 Aug 2014 07:25:45 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id D5D79B00085; Mon, 11 Aug 2014 07:26:20 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Vj12tHFAmw-7; Mon, 11 Aug 2014 07:26:20 -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 916ABB0007B; Mon, 11 Aug 2014 07:26:19 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <53E8A447.5080303@gmail.com> Date: Mon, 11 Aug 2014 12:26:16 +0100 Cc: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <2B6755F2-74F7-4D4D-99CC-319BFF78F2DF@ajf.me> References: <53DF2BED.10103@sugarcrm.com> <06F3EF08-21B1-49AD-9D9D-5043C69AC1D8@ajf.me> <53DFE1FC.5040206@gmail.com> <4c89fa2a-a4da-46a9-9872-6d2e5346fed1@email.android.com> <7AC9A96B-9B45-45B2-BBD1-1E61CC6075E8@ajf.me> <53E8A447.5080303@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Closure::call and Function Referencing as Closures From: ajf@ajf.me (Andrea Faulds) On 11 Aug 2014, at 12:08, Rowan Collins wrote: > I understand that &$foo->method won't work, but that's what I mean by = pre-supposing the proposed syntax. >=20 > If you had a different syntax, such as =A3function (I know it's not a = sensible choice, but it's an example of something with no conflict), you = *would* be able to implement =A3$foo->method. It would "do the same = thing calls do", which is call a non-static method non-statically. >=20 > So the question is, is it a) desirable and b) practical to come up = with an implementation where that is possible? Ah, I see what you=92re saying. It=92s certainly worth thinking about. & = isn=92t really the nicest of syntaxes. > Yep, that's my point - referencing a method without also referencing = the class or object it's bound to is not something that usually happens = in PHP, so it feels odd to make it the default behaviour here. >=20 > Your proposal requires that to create a reference to a non-static = method of the current object, you would do something like this: >=20 > $foo =3D &static::foo; > $foo->bindTo($this); >=20 > We could imagine instead having a factory like Closure::wrap(callable = $c), where the exact equivalent would be: >=20 > $foo =3D Closure::wrap([static::class, 'foo']); > $foo->bindTo($this); >=20 > But you would never write it that way, because we have a way of = specifying callables for instance methods, so you'd just write this: >=20 > $foo =3D Closure::wrap([$this, 'foo']); >=20 > You might for some reason want to re-bind that to a different object = (although I'm not sure why, outside of things you'd expect to use = Reflection for anyway), but the default would be referencing its = existing binding. I think Closure::bind(&FooBar::foo, =91FooBar=92); works well, but yes, = I can see your point. > In which case what do you think of my second suggestion, of adding = methods to allow people to tell whether a closure is bound, bindable, = etc? It makes it much easier to write defensive code if you can predict = errors rather than catching them. I=92m totally in favour of that. One thing I=92d like to see, if we = introduce references for functions and classes and so on, is more = reflection-like stuff. I think it=92s a bit silly to have to instantiate = reflection classes all the time. Given that closures are already = objects, I see no reason why you should need to use ReflectionFunction = on them. Rather, we should provide all this information on the object = directly. -- Andrea Faulds http://ajf.me/