Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38469 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78377 invoked from network); 20 Jun 2008 15:11:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2008 15:11:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=chris_se@gmx.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=chris_se@gmx.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.net designates 213.165.64.20 as permitted sender) X-PHP-List-Original-Sender: chris_se@gmx.net X-Host-Fingerprint: 213.165.64.20 mail.gmx.net Linux 2.5 (sometimes 2.4) (4) Received: from [213.165.64.20] ([213.165.64.20:50636] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/7E-16112-603CB584 for ; Fri, 20 Jun 2008 10:47:35 -0400 Received: (qmail invoked by alias); 20 Jun 2008 14:47:31 -0000 Received: from p54A17093.dip.t-dialin.net (EHLO chris-se.dyndns.org) [84.161.112.147] by mail.gmx.net (mp036) with SMTP; 20 Jun 2008 16:47:31 +0200 X-Authenticated: #186999 X-Provags-ID: V01U2FsdGVkX1+S0/o8/jyS61Jb85IjTDUj/3QBEIgF7F+TxU8n4D O6NlYcoOvpJ55H Received: from [192.168.0.175] (HSI-KBW-091-089-005-213.hsi2.kabelbw.de [91.89.5.213]) by chris-se.dyndns.org (Postfix) with ESMTP id D9BA2106F0; Fri, 20 Jun 2008 16:34:09 +0200 (CEST) Message-ID: <485BC2D0.4080709@gmx.net> Date: Fri, 20 Jun 2008 16:46:40 +0200 User-Agent: Thunderbird 2.0.0.14 (X11/20080421) MIME-Version: 1.0 To: Alexander Wagner CC: internals@lists.php.net, Larry Garfield References: <4856A547.3080801@gmx.net> <485B5BCC.1060003@city.ee> <200806200729.40623.larry@garfieldtech.com> <200806201633.08425.waqner@gmx.net> In-Reply-To: <200806201633.08425.waqner@gmx.net> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: chris_se@gmx.net (Christian Seiler) Hi, >> I would be fine with requiring an explicit declaration of $this if it helped >> avoid memory leaks. > > I would propose to always require explicit declaration of $this, even if there > is no memory-leak problem. This would make it easier to distinguish plain > lambdas from closures and would prevent closures from being created by > accident. I believe that is not neessary: $this is not a normal variable in PHP (see for example or ) but a language construct. So it is possible to determine if this is used at compile time (if $this is used inside the function, op_array->this_var != -1 if I'm not mistaken) - and therefore automatically importing it (it is automatically available in local scope of class methods anyway). The only possible clash could be nested lambdas - but there you could simply enforce the creation of $this in all functions containing a lambda which uses $this). To sum it up: I believe it is possible to optimize it that way that $this is only stored within the closure if the closure actually needs it - but without the need for declaring it explicitly. Regards, Christian