Re: Re: dynamically selecting a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hmm, there is an intresting way that AFAIK only exists in PHP which is the 
variable variable and variable function.
That is you could have a string to be a function name and then make the call 
with it in the following manner:
$step=1;
$func_const_name="step";
$dyn_func=$func_const_name.$step;
 and then the function call would look like
$dyn_func(); // which would result in step1();
 How about that? isnt it so beautiful? God Bless ZEND

 On 8/8/05, Norbert Wenzel <mail@xxxxxxxxxxxx> wrote: 
> 
> Thomas wrote:
> > Thanks Burhan. Is there much overhead?
> >
> > Norbert: that's what I am doing now, just wanted to save some code. :-)
> >
> > Thomas
> >
> > -----Original Message-----
> > From: Norbert Wenzel [mailto:mail@xxxxxxxxxxxx]
> > Sent: 08 August 2005 11:18 AM
> > To: php-general@xxxxxxxxxxxxx
> > Subject:  Re: dynamically selecting a function
> >
> > Thomas wrote:
> >
> >>Hi there,
> >>
> >>
> >>
> >>How can I do something like this:
> >>
> >>
> >>
> >>[snip - theoretical code] if( isset($step) ) echo step.$step() ) [/snip]
> >>
> >>
> >>
> >>$step would be an int (I would check that before) and then I would have
> >
> > all
> >
> >>sorts of functions like step1(), step2() . etc.
> >>
> >>
> >>
> >>Any ideas?
> >>
> >>
> >>
> >>Thomas
> >
> >
> > What about switch / case?
> >
> > switch($step) {
> > case 1:
> > step1();
> > break;
> > case 2:
> > step2();
> > break;
> > default:
> > defaultStep();
> > break;
> > }
> >
> 
> i thought that would be too easy ;-)
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
M.Saleh.E.G
97150-4779817

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux