Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7528 invoked from network); 11 Aug 2010 13:38:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2010 13:38:16 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:57118] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/B0-01618-4C7A26C4 for ; Wed, 11 Aug 2010 09:38:13 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 831097001EDC for ; Wed, 11 Aug 2010 14:38:09 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id daI1vOWINMGy for ; Wed, 11 Aug 2010 14:38:09 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 412E77001B11 for ; Wed, 11 Aug 2010 14:38:09 +0100 (WEST) Received: from cataphract-old.dulce.lo.geleia.net (52.152.108.93.rev.vodafone.pt [93.108.152.52]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 297E42006C4E for ; Wed, 11 Aug 2010 14:38:09 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "internals@lists.php.net" Date: Wed, 11 Aug 2010 14:38:14 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: User-Agent: Opera Mail/10.60 (Win32) Subject: Closures as methods (and Closure::bind) From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") I've updated the wiki page for "Closures with objects extension" with = things that are in "Proposal A with modification"s but are not implement= ed: http://wiki.php.net/rfc/closures/object-extension#status_as_of_august_10= _2010 I propose an implementation of "closures stored in properties used as = methods", as in: $this->prop =3D function () { ...} $this->prop(); A few issues that may merit discussion (copied from the wiki page): - Do we really want to make closures-as-methods have priority over = __call/__callStatic? On one hand, there's no way to otherwise allow = closures-as-methods in classes that implement these magic methods, on th= e = other one, this breaks BC and makes the magic methods even more = inefficient =E2=80=93 we have to check if there is a method and a proper= ty with = that name. - Properties are not case-sensitive, hence calling closures-as-methods i= s = case-sensitive (contrary to calling regular methods). - What to do with properties with no visibility? Ignore them (and let fa= ll = back to __call/__callStatic) or raise error (the implementation in the = patch raises an error). - What to do with properties used as methods that are not closures? Igno= re = them or raise an error (the implementation raises an error). - Should we throw an exception when calling a closure-as-instance method= = that's stored as a static method? Usually, accessing a static property i= n = a non static context raises an E_STRICT, but I think may very well be ve= ry = useful, because we can swap instance method implementations on a class = basis instead of only an instance basis. I've also updated the "bindTo" behavior change and document it in the sa= me = wiki page. Compared to the previous patch I'd sent, this implementation = = has more tests, moves getScope to reflection (a getClosureScopeClass tha= t = returns a ReflectionClass) and allows binding objects with NULL scope = (uses a dummy scope instead) instead of silently refusing to bind the = object. -- = Gustavo Lopes