Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38650 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50911 invoked from network); 26 Jun 2008 21:09:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2008 21:09:00 -0000 Authentication-Results: pb1.pair.com header.from=chris_se@gmx.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chris_se@gmx.net; spf=pass; 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.6 Received: from [213.165.64.20] ([213.165.64.20:44967] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/6A-17914-B6504684 for ; Thu, 26 Jun 2008 17:09:00 -0400 Received: (qmail invoked by alias); 26 Jun 2008 21:08:56 -0000 Received: from p54A16787.dip.t-dialin.net (EHLO chris-se.dyndns.org) [84.161.103.135] by mail.gmx.net (mp043) with SMTP; 26 Jun 2008 23:08:56 +0200 X-Authenticated: #186999 X-Provags-ID: V01U2FsdGVkX198yc8qZ1p87bhc24JCOT7wiJjpDZLpCNbsbfb0S9 eeseeB9hbXGPXn 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 907DB10B8D; Thu, 26 Jun 2008 22:52:04 +0200 (CEST) Message-ID: <4864052D.1070500@gmx.net> Date: Thu, 26 Jun 2008 23:07:57 +0200 User-Agent: Thunderbird 2.0.0.14 (X11/20080421) MIME-Version: 1.0 To: Alexander Wagner CC: internals@lists.php.net, Dmitry Stogov , Andi Gutmans , Stanislav Malyshev References: <4856A547.3080801@gmx.net> <485B908D.7000106@zend.com> <4863C299.1080002@gmx.net> <200806262246.24193.waqner@gmx.net> In-Reply-To: <200806262246.24193.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 see exactly one problem with the patch, which is that the above script > shouldn't work without "use (&$i)". > I find it counterintuitive that the creation of the lambda creates a copy of > $i, but all invocations of $lambda use a reference to the same $i. > For n calls to $lambda, there are only 2 copies of $i (one global, one static > in $lambda) where I would expect n+1 copies. Yes, you're right. My solution for this would be: -------------- zend_compile.h ------------------------- -void zend_do_fetch_static_variable(znode *varname, znode *static_assignment, int fetch_type TSRMLS_DC); +void zend_do_fetch_static_variable(znode *varname, znode *static_assignment, int fetch_type, int as_ref TSRMLS_DC); -------------- zend_compile.h ------------------------- -------------- zend_compile.c ------------------------- # in zend_do_fetch_lexical_variable: -zend_do_fetch_static_variable(varname, &value, ZEND_FETCH_STATIC TSRMLS_CC); +zend_do_fetch_static_variable(varname, &value, ZEND_FETCH_STATIC, is_ref TSRMLS_CC); ... -void zend_do_fetch_static_variable(znode *varname, znode *static_assignment, int fetch_type TSRMLS_DC) +void zend_do_fetch_static_variable(znode *varname, znode *static_assignment, int fetch_type, int as_ref TSRMLS_DC) ... - zend_do_assign_ref(NULL, &lval, &result TSRMLS_CC); + if (as_ref) { + zend_do_assign_ref(NULL, &lval, &result TSRMLS_CC); + } else { + zend_do_assign(NULL, &lval, &result TSRMLS_CC); + } # and make sure zend_do_assign can live with NULL for first param -------------- zend_compile.c ------------------------- -------------- zend_language_parser.y ------------------------- static_var_list: - static_var_list ',' T_VARIABLE { zend_do_fetch_static_variable(&$3, NULL, ZEND_FETCH_STATIC TSRMLS_CC); } - | static_var_list ',' T_VARIABLE '=' static_scalar { zend_do_fetch_static_variable(&$3, &$5, ZEND_FETCH_STATIC TSRMLS_CC); } - | T_VARIABLE { zend_do_fetch_static_variable(&$1, NULL, ZEND_FETCH_STATIC TSRMLS_CC); } - | T_VARIABLE '=' static_scalar { zend_do_fetch_static_variable(&$1, &$3, ZEND_FETCH_STATIC TSRMLS_CC); } + static_var_list ',' T_VARIABLE { zend_do_fetch_static_variable(&$3, NULL, ZEND_FETCH_STATIC, 1 TSRMLS_CC); } + | static_var_list ',' T_VARIABLE '=' static_scalar { zend_do_fetch_static_variable(&$3, &$5, ZEND_FETCH_STATIC, 1 TSRMLS_CC); } + | T_VARIABLE { zend_do_fetch_static_variable(&$1, NULL, ZEND_FETCH_STATIC, 1 TSRMLS_CC); } + | T_VARIABLE '=' static_scalar { zend_do_fetch_static_variable(&$1, &$3, ZEND_FETCH_STATIC, 1 TSRMLS_CC); } ; -------------- zend_language_parser.y ------------------------- Any objections (in case copies are wanted at all)? Regards, Christian