call a function

Discussion in 'PHP' started by TG_Kenneth, Oct 18, 2008.

  1. #1
    hello,
    is it possible to call a function depending on a variable value? and how?

    example:

    
    $f_name = "abc";
    
    $f_name();  // <--I wanna call abc() here, how to do it?
    
    PHP:
    thanks!
     
    TG_Kenneth, Oct 18, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That is how you do it. You did it exactly right
     
    Kyosys, Oct 18, 2008 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    You may want to verify it with is_callable before actually attempting to call it.
     
    joebert, Oct 18, 2008 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    
    <?php
    function testme(){ echo 'test';}
    $myfunction = 'testme';
    ${myfunction}();
    ?>
    
    PHP:
    Peace,
     
    Barti1987, Oct 18, 2008 IP
  5. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you don't really need the curly brackets, though
     
    Kyosys, Oct 19, 2008 IP