How to get argument name for some function?

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

    #1

    How to get argument name for some function?

    For example:

    function test($left, $right)
    {
    }

    $ret = some_php_api('t est');

    print_r($ret);

    //it would be
    /*
    array(
    1 ='left',
    2 ='right',
    )
    */

  • doug turnbull

    #2
    Re: How to get argument name for some function?


    Yarco wrote:
    For example:
    >
    function test($left, $right)
    {
    }
    >
    $ret = some_php_api('t est');
    >
    print_r($ret);
    >
    //it would be
    /*
    array(
    1 ='left',
    2 ='right',
    )
    */
    I can't help you with your main question.

    However, assuming this is a function you control, could you track this
    yourself?

    $arg1 = "left";
    $arg2 = "right";

    #And maybe:

    function_args['test']['arg1'] = $arg1;
    function_args['test']['arg1'] = $arg2;

    function test($$arg1, $$arg2)
    {
    #Should work
    echo $left;
    echo $right;
    }

    Somebody should confirm the code above and make sure I'm not insane,
    but feel free to try it out, I think it should work.

    Comment

    • AlexVN

      #3
      Re: How to get argument name for some function?



      On Nov 1, 5:41 am, "Yarco" <yarc...@gmail. comwrote:
      For example:
      >
      function test($left, $right)
      {
      >
      }$ret = some_php_api('t est');
      >
      print_r($ret);
      >
      //it would be
      /*
      array(
      1 ='left',
      2 ='right',
      )
      */
      Reflection is your friend.
      function q($a, $b) {
      $result = array();
      $reflection = new ReflectionFunct ion(__FUNCTION_ _);
      foreach ($reflection->getParameters( ) as $param) {
      $result[$param->getName()] = ${$param->getName()};
      }
      return $result;
      }

      print_r(q(1, 2));

      Sincerely,
      Alexander
      http://www.alexatnet.com/ - PHP/ZendFramework/Ajax blog

      Comment

      • Yarco

        #4
        Re: How to get argument name for some function?

        Thanks, Alex

        AlexVN wrote:
        On Nov 1, 5:41 am, "Yarco" <yarc...@gmail. comwrote:
        For example:

        function test($left, $right)
        {

        }$ret = some_php_api('t est');

        print_r($ret);

        //it would be
        /*
        array(
        1 ='left',
        2 ='right',
        )
        */
        >
        Reflection is your friend.
        function q($a, $b) {
        $result = array();
        $reflection = new ReflectionFunct ion(__FUNCTION_ _);
        foreach ($reflection->getParameters( ) as $param) {
        $result[$param->getName()] = ${$param->getName()};
        }
        return $result;
        }
        >
        print_r(q(1, 2));
        >
        Sincerely,
        Alexander
        http://www.alexatnet.com/ - PHP/ZendFramework/Ajax blog

        Comment

        Working...