Re: Re: [Text_Highlight] eval() Vs call_user_func()...

From: Date: Thu, 08 Apr 2004 10:42:15 +0000
Subject: Re: Re: [Text_Highlight] eval() Vs call_user_func()...
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-27175@lists.php.net to get a copy of this message
On 8 Apr 2004 at 0:27, Davey wrote: > Justin Patrin wrote: > > Davey wrote: > > > >> I've been doing some tests after a comment on using eval() in > >> Text_Highlight I went and modified it to use call_user_func(). > >> > >> Afterwards I decided to benchmark it using Benchmark_Iterate, > >> and have come up with the following surprising results: > >> > >> Using call_user_func(): > >> array(2) { > >> ["mean"]=> > >> string(8) "0.027010" > >> ["iterations"]=> > >> int(1000) > >> } > >> > >> Using eval(): > >> array(2) { > >> ["mean"]=> > >> string(8) "0.026098" > >> ["iterations"]=> > >> int(1000) > >> } > >> > >> Surprising to me. Not enough to cause any reason to choose one over > >> the other.... and I've chosen call_user_func() because I'm from the > >> school of "if eval() is the answer, you're asking the wrong question". > >> > >> - Davey > > > > > > Why not use indirection instead? > > > > $funcName = 'functionToCall'; > > $funcName(1, 2, 3); > > > > Does not work like this: > > $func = "Text_Highlight_Php::highlight"; > $func($code); Have you tried with an array? $func = array("Text_Highlight_Php", "highlight"); $func($code); Got no possiblity to test it yet. But that's how call_user_func of php wants the call also, so maybe it would work with the indirection this way also. http://de2.php.net/manual/en/function.call-user-func.php Good luck, Stefan

« previous php.pear.dev (#27175) next »