address of functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard

    address of functions


    Is it possible to store the address or reference to a function in php? Maybe
    using just a string and later dereferencing it?

    e.g some ideas to illustrate what I mean

    <?php
    function myCompanyMotto( ){
    echo "hello";
    }

    $myarr["func1"]=&myCompanyMott o;
    $myarr["func2"]="myCompanyMott o";

    //how to get function from myarr and call it????

    ?>


    --
  • Rik

    #2
    Re: address of functions

    On Tue, 20 Feb 2007 22:53:14 +0100, Richard <rgrdev@gmail.c omwrote:
    >
    Is it possible to store the address or reference to a function in php?
    Maybe
    using just a string and later dereferencing it?
    >
    e.g some ideas to illustrate what I mean
    >
    <?php
    function myCompanyMotto( ){
    echo "hello";
    }
    >
    $myarr["func1"]=&myCompanyMott o;
    $myarr["func2"]="myCompanyMott o";
    >
    //how to get function from myarr and call it????
    >
    ?>
    I'd just use call_user_func( )/call_user_func_ array(), and save the
    callback either as a string for normal functions, and as an array for
    object/class methods.

    function myCompanyMotto( ){
    echo "hello";
    }
    class foo{
    function bar(){
    echo 'class';
    }
    }
    $myarr['func1'] = 'myCompanyMotto ';
    $myarr['func2'] = array('foo','ba r');
    call_user_func( $myarr['func1']);
    call_user_func( $myarr['func2']);
    --
    Rik Wasmus

    Comment

    • Richard

      #3
      Re: address of functions

      Rik <luiheidsgoeroe @hotmail.comwri tes:
      On Tue, 20 Feb 2007 22:53:14 +0100, Richard <rgrdev@gmail.c omwrote:
      >
      >>
      >Is it possible to store the address or reference to a function in
      >php? Maybe
      >using just a string and later dereferencing it?
      >>
      >e.g some ideas to illustrate what I mean
      >>
      ><?php
      >function myCompanyMotto( ){
      > echo "hello";
      >}
      >>
      >$myarr["func1"]=&myCompanyMott o;
      >$myarr["func2"]="myCompanyMott o";
      >>
      >//how to get function from myarr and call it????
      >>
      >?>
      >
      I'd just use call_user_func( )/call_user_func_ array(), and save the
      callback either as a string for normal functions, and as an array for
      object/class methods.
      >
      function myCompanyMotto( ){
      echo "hello";
      }
      class foo{
      function bar(){
      echo 'class';
      }
      }
      $myarr['func1'] = 'myCompanyMotto ';
      $myarr['func2'] = array('foo','ba r');
      call_user_func( $myarr['func1']);
      call_user_func( $myarr['func2']);
      Thanks, I had googled, but being new to PHP I hadnt found
      call_user_func. Just what I want.

      Comment

      • Kimmo Laine

        #4
        Re: address of functions

        "Richard" <rgrdev@gmail.c omwrote in message
        news:878xesv6lx .fsf@gmail.com. ..
        >
        Is it possible to store the address or reference to a function in php?
        Maybe
        using just a string and later dereferencing it?
        >
        e.g some ideas to illustrate what I mean
        >
        <?php
        function myCompanyMotto( ){
        echo "hello";
        }
        >
        $myarr["func1"]=&myCompanyMott o;
        $myarr["func2"]="myCompanyMott o";
        >
        //how to get function from myarr and call it????
        >

        function foo(){
        echo "Hello Kitty!";
        }

        $bar = 'foo';

        $bar();


        --
        "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
        http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
        spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


        Comment

        Working...