How to get the source code of a method/function call?

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

    How to get the source code of a method/function call?

    Currently, I use this call

    traceVariable( $_SERVER['PHP_SELF'], '$_SERVER["PHP_SELF"]' );

    to pass a variable by reference to 'traceVariable' and by value a
    description string.

    Since the description string is very likely to be identical to the
    source code (string) of the first parameter, I'd like to write this:

    traceVariable( $_SERVER['PHP_SELF'] );

    Any ideas, how to get the literal expression (source) of a parameter,
    which got passed to a method/function?

  • Andy Hassall

    #2
    Re: How to get the source code of a method/function call?

    On 16 Dec 2006 15:23:19 -0800, "seaside" <seaside.ki@mac .comwrote:
    >Currently, I use this call
    >
    traceVariable( $_SERVER['PHP_SELF'], '$_SERVER["PHP_SELF"]' );
    >
    >to pass a variable by reference to 'traceVariable' and by value a
    >description string.
    >
    >Since the description string is very likely to be identical to the
    >source code (string) of the first parameter, I'd like to write this:
    >
    traceVariable( $_SERVER['PHP_SELF'] );
    >
    >Any ideas, how to get the literal expression (source) of a parameter,
    >which got passed to a method/function?
    See the thread "Easy question, return variable name" from just 2 days ago.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • seaside

      #3
      Re: How to get the source code of a method/function call?


      Andy Hassall schrieb:
      On 16 Dec 2006 15:23:19 -0800, "seaside" <seaside.ki@mac .comwrote:
      >
      Since the description string is very likely to be identical to the
      source code (string) of the first parameter, I'd like to write this:

      traceVariable( $_SERVER['PHP_SELF'] );

      Any ideas, how to get the literal expression (source) of a parameter,
      which got passed to a method/function?
      >
      See the thread "Easy question, return variable name" from just 2 days ago.
      Ok, no standard method available. Then, I'll use backtrace to construct
      'something'.

      Comment

      • Dikkie Dik

        #4
        Re: How to get the source code of a method/function call?

        You can use the eval function to go the other way around (not tested):

        function traceVariable($ name)
        {echo $name . ' = ' . var_export(eval ('return ' . $name), TRUE);}

        You'd call it with traceVariable(' $_SERVER[\'PHP_SELF\']');


        seaside wrote:
        Andy Hassall schrieb:
        >
        >On 16 Dec 2006 15:23:19 -0800, "seaside" <seaside.ki@mac .comwrote:
        >>
        >>Since the description string is very likely to be identical to the
        >>source code (string) of the first parameter, I'd like to write this:
        >>>
        >> traceVariable( $_SERVER['PHP_SELF'] );
        >>>
        >>Any ideas, how to get the literal expression (source) of a parameter,
        >>which got passed to a method/function?
        > See the thread "Easy question, return variable name" from just 2 days ago.
        >
        Ok, no standard method available. Then, I'll use backtrace to construct
        'something'.
        >

        Comment

        • seaside

          #5
          Re: How to get the source code of a method/function call?


          Dikkie Dik schrieb:
          You can use the eval function to go the other way around (not tested):
          >
          function traceVariable($ name)
          {echo $name . ' = ' . var_export(eval ('return ' . $name), TRUE);}
          >
          You'd call it with traceVariable(' $_SERVER[\'PHP_SELF\']');
          Hey, nice idea!

          If PHP had a preprocessor, I could even prepare a #define() macro,
          which
          passes the passed literla-string and its expression along.
          Unfortunately, I don't
          know of any.

          Comment

          Working...