Re: svn: /phpdoc/en/trunk/ language/types/pseudo-types.xml reference/pcre/functions/preg-replace-callback.xml

From: Date: Thu, 30 Jul 2009 15:34:43 +0000
Subject: Re: svn: /phpdoc/en/trunk/ language/types/pseudo-types.xml reference/pcre/functions/preg-replace-callback.xml
References: 1 2 3  Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4570@lists.php.net to get a copy of this message
I think that create_function() is the real evil because it is evaluated in the runtime again and again. Anonymous functions on the contrary are evaluated in the compile time so using them in a callback repeatedly is not a problem. Simple benchmark confirms this thesis: function f($match) { return $match[0]; } preg_replace_callback('(a)', 'f', 'aaa'): 0.094 s for 10000 calls preg_replace_callback('(a)', function ($match) { return $match[0]; }, 'aaa'): 0.091 s for 10000 calls preg_replace_callback('(a)', create_function('$match', 'return $match[0];'), 'aaa'): 0.296 s for 10000 calls + memory limit exhausted Jakub Vrana 2009/7/30 Hannes Magnusson <hannes.magnusson@gmail.com>: > On Thu, Jul 30, 2009 at 11:20, Jakub Vrana<vrana@php.net> wrote: > [..] >> Modified: phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback..xml >> =================================================================== >> --- phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback.xml  2009-07-30 >> 08:08:37 UTC (rev 286542) >> +++ phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback.xml  2009-07-30 >> 09:20:16 UTC (rev 286543) >> @@ -48,7 +48,9 @@ >>       <para> >>        You'll often need the <parameter>callback</parameter> function >>        for a <function>preg_replace_callback</function> in just one place. >> -       In this case you can use <function>create_function</function> to >> +       In this case you can use an >> +       <link linkend="functions.anonymous">anonymous >> function</link> (since >> +       PHP 5.3.0) or <function>create_function</function> to > > Do we really have to mention this for all functions taking callbacks? > > The examples are obviously good to have, but explicitly mentioning > what the callback type means and the fact you can pass anonymous > functions to it again and again and again..? > > -Hannes > > -- > PHP Documentation Commits Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.doc.cvs (#4570) next »