Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38797 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52693 invoked from network); 7 Jul 2008 04:19:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jul 2008 04:19:47 -0000 Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.162 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 212.25.124.162 mail.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.162] ([212.25.124.162:60391] helo=mx1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/F5-02622-26991784 for ; Mon, 07 Jul 2008 00:19:47 -0400 Received: from us-ex1.zend.com ([192.168.16.5]) by mx1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 7 Jul 2008 07:20:06 +0300 Received: from [192.168.17.79] ([192.168.17.79]) by us-ex1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Sun, 6 Jul 2008 21:20:03 -0700 Message-ID: <48719958.8030105@zend.com> Date: Sun, 06 Jul 2008 21:19:36 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Marcus Boerger CC: Christian Seiler , php-dev List References: <486B6960.4030705@gmx.net> <1264378041.20080705215006@marcus-boerger.de> In-Reply-To: <1264378041.20080705215006@marcus-boerger.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 07 Jul 2008 04:20:03.0477 (UTC) FILETIME=[BA856450:01C8DFE8] Subject: Re: [PHP-DEV] [RFC] Closures: updated proposal and patch From: stas@zend.com (Stanislav Malyshev) Hi! > function replace_spaces ($text) { > static $replacement = function ($matches) { > return str_replace ($matches[1], ' ', ' ').' '; > }; > return preg_replace_callback ('/( +) /', $replacement, $text); > } > > That is using static would result in creating the function only once. I'm not sure this exactly one would work, as closure is not a constant expression and thus its use as initializer may not work. However, converting it to pseudo-singleton may work: static $replacement = null; if($replaceement == null) { $replacement = function { blah-blah } } -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com