Re: How expensive are function_exists() calls?

From: Date: Fri, 13 Mar 2009 04:55:05 +0000
Subject: Re: How expensive are function_exists() calls?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-289972@lists.php.net to get a copy of this message
For templating ideas ... Would bytecode caches (APC) be able to work properly with this: function print_something($args, $output = 'html') { switch($output) { 'iphone': print_something_iphone($args); break; default: print_something_html($args); break; } } or something like this: function print_something($args, $output = 'html') { if(function_exists('print_something_'.$output)) { call_user_func('print_something_'.$output); } } On Wed, Mar 4, 2009 at 12:45 PM, mike <mike503@gmail.com> wrote: > On Wed, Mar 4, 2009 at 4:01 AM, Jochem Maas <jochem@iamjochem.com> wrote: >> ..not an internals question me thinks ... redirecting to generals mailing list > > Actually, I do think it is somewhat internals related. > > I want to know from the internals/experts angle if this is a good > function to be relying on, or if it is one of those things like the > "@" operator which I've been told is "expensive" and to me is one of > those things to stay away from. > > Now if this breaks opcode caches like APC, I will have to find another way. > > Also - I write procedural, not OOP. So that won't help here. > > Would creating functions such as > > output_foo_html() > output_foo_rss() > output_foo_json() > > Then depending on the output, using something like this? Would this be > breaking opcode caches as well then? > > if(function_exists('output_foo_'.$format)) { >    call_user_func('output_foo_'.$format); > } else { >    output_foo_html(); > } >

« previous php.general (#289972) next »