Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43241 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73873 invoked from network); 4 Mar 2009 11:42:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Mar 2009 11:42:39 -0000 Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.44.30 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 74.125.44.30 yx-out-2324.google.com Received: from [74.125.44.30] ([74.125.44.30:56036] helo=yx-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/00-07946-D296EA94 for ; Wed, 04 Mar 2009 06:42:37 -0500 Received: by yx-out-2324.google.com with SMTP id 8so1926908yxb.83 for ; Wed, 04 Mar 2009 03:42:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=RNZVacXziqXizj3KhSz3UFTIUqyH8ceS2fE2q3hgCSk=; b=dNwPlN83mFDoZNpMXQ9we+uLOgDfRrUsKsgG+Oc+6Xlf3ceBcJuv7mWVNmqJH+1iFG Gb2/GnjGIFQ7zca325FWWJxWSVJ86vsg/k59C7TTRJQg1qewq0bBI4Q/hp+VYZtI/5FF F5stsWIOaIe6ZkVXvH9Km1iyHXD0kR/gZtffk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=VhhyyVpAsrbF4Vf5/HgtmZWCGnhfh/SMuEkaVNl8RjVYzsVwBRg90YCTCs0b4+ngaO p1qMBgiv8GPZmM8T+V9yPNbHcX6iun4evUc0N8bBBqwjeMdq8lfDq/QbwhFw0UxjDJkR ZN9VxQZGYJCCsTczfPR7dNC8c/MepGUtOb6NI= MIME-Version: 1.0 Received: by 10.100.42.4 with SMTP id p4mr2662007anp.115.1236166954703; Wed, 04 Mar 2009 03:42:34 -0800 (PST) In-Reply-To: <10845a340903040333g5fd001fdw73fc17eacbd968c9@mail.gmail.com> References: <10845a340903040333g5fd001fdw73fc17eacbd968c9@mail.gmail.com> Date: Wed, 4 Mar 2009 14:42:34 +0300 Message-ID: To: RQuadling@googlemail.com Cc: PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Are there plans to allow anonymous functions as callbacks? From: indeyets@gmail.com (Alexey Zakhlestin) On Wed, Mar 4, 2009 at 2:33 PM, Richard Quadling wrote: > Hi. > > Quite a simple question (assuming I've got the terminology correct). > > Are there any plans to allow code like this (amended example taken > from the array_map() documentation) ... > > $a =3D array(1, 2, 3, 4, 5); > $b =3D array_map(function($n){return($n * $n * $n)}, $a); > print_r($b); > > For me, this is cleaner than having a use-once, namespace-polluting funct= ion. > > Currently, this is producing a parse error. It works. You have a typo. You need to put ";" after return (=E2=80=A6) > > > A real alternative though would be to allow nested functions... > > function cube_array($a) { > =C2=A0function cube($n) { > =C2=A0 =C2=A0return($n * $n * $n); > =C2=A0} > =C2=A0return array_map("cube", $a); > } > $a =3D array(1, 2, 3, 4, 5); > $b =3D cube_array($a); > print_r($b); > > Ideally, cube() would not be visible outside of cube_array(). Scoped func= tions. > > Regards, > > Richard Quadling. > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D2134= 74731 > "Standing on the shoulders of some very clever giants!" > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Alexey Zakhlestin http://www.milkfarmsoft.com/