473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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?

Dec 16 '06 #1
4 2621
On 16 Dec 2006 15:23:19 -0800, "seaside" <se********@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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 16 '06 #2

Andy Hassall schrieb:
On 16 Dec 2006 15:23:19 -0800, "seaside" <se********@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'.

Dec 16 '06 #3
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" <se********@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'.
Dec 17 '06 #4

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.

Dec 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Bill Marsden | last post by:
Hi. I am an under-graduate currently studying Open Source (Linux) vs Closed Source and Collaboration within the IT Community. I am fairly new to Javascript and I have written a "Lottery Program"...
7
by: Jean-Marc Blaise | last post by:
Hi, The dev center calls sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj') to update the sqlj routine source. I tried in CLP from the directory containing jar and sqlj files (Windows...
6
by: Xing Xu | last post by:
Hi guiders, sorry , since I don't know which group suit for this question,I just post this question at these group. As we know , we can get the run-time call graph by some proved tools . now...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
8
by: Alvo von Cossel I | last post by:
hey everybody, I have written a great browser but it is missing a feature (quite a lot actually, but forget about them for now). that feature just so happens to be the View > Source function....
2
by: Maellic | last post by:
Hi, I'm currently updating a website written with ASP.NET. The original programmer is overseas, there is no documentation, and files are all over the place. Here is a code snippet from one of...
2
by: Dale Sampson | last post by:
My app uses an ODBC connection for a .mdb file. I want the app to create the source if it does not already exist (I copy a blank .mdb file to the users data store if it doesn't exist). I see how...
4
by: Pyenos | last post by:
#!/usr/bin/python #################################################### # answers.py --- A simple answer bot # Copyright (C) 2006 Logan Lee # # MESSAGE: # # This program is a simple...
6
by: Paul Wilson | last post by:
Hi all, I'd like to be able to do the following to a python source file programmatically: * Read in a source file * Add/Remove/Edit Classes, methods, functions * Add/Remove/Edit Decorators *...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.