Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts

    Can I pass a function name to a function and then call that function?

    I'm not where I can try this, otherwise I would just try it. Can you send a function name as an argument to a function, then call that function from within the called function? For example:

    PHP Code:
    myFunction ("calculateSomething");


    function 
    myFunction ($funcName) }

        
    $a $funcName();

        echo 
    $a//should be 2
    }


    function 
    calculateSomething() {

        return 
    1;



  • #2
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    Last edited by eak; 12-08-2008 at 04:10 PM. Reason: added link
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • Users who have thanked eak for this post:

    Fumigator (12-08-2008)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Callback's baby ;D, the closest thing PHP gets to function pointers.

    I'd actually recommend using the execution function with call_user_func or call_user_func_array. I suggest this for situations where you'll be using an object callback, which pre-5.3 I believe it is it doesn't tend to like the Paamayim Nekudotayim accessor for class methods for variable functions (as in, a function that is a variable).
    Now, let hope that zend promotes callback to an object so we can at least typecast the function to require one.

    Callback link (which is tough to find): http://us3.php.net/manual/en/languag...types.callback
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Fumigator (12-08-2008)

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Hey, that's what I want, a callback. Awesome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •