473,795 Members | 3,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Echo the actual Variable name

So i sit here thinking, and wondering...

say for example i have a variable called $definition_lon don

Say for exaple that has not set value...

Is it possible to echoe thew ACTUAL variable name into a document, rather
than the variables information?

Thanks for yout time, look forward to all replies :)
Feb 20 '06 #1
7 25430
"Dawsons" <st****@3branch .co.uk> wrote in message
news:Aa******** ***********@new sfe4-win.ntli.net...
So i sit here thinking, and wondering...

say for example i have a variable called $definition_lon don

Say for exaple that has not set value...

Is it possible to echoe thew ACTUAL variable name into a document, rather
than the variables information?

Thanks for yout time, look forward to all replies :)

I'm no sure what you are exactly looking for, but you could do something
like this:

echo 'Here is a list of all variables and their values defined in this
script:<br />';
print_r(get_def ined_vars());

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi. net | Gedoon-S @ IRCnet | rot13(xv***@bhg byrzcv.arg)
Feb 20 '06 #2
echo '$definition_lo ndon is in a string';

Feb 20 '06 #3
Dawsons wrote:
Is it possible to echoe thew ACTUAL variable name into a document


function getvarname(&$va r)
{
$ret = '';
$tmp = $var;
$var = md5(uniqid(rand (), TRUE));

$key = array_keys($GLO BALS);
foreach ( $key as $k )
if ( $GLOBALS[$k] === $var )
{
$ret = $k;
break;
}

$var = $tmp;
return $ret;
}

$another = 'test';
$testvar = 'test';
echo getvarname($tes tvar); //echoes 'testvar'

--
E. Dronkert
Feb 20 '06 #4
Thank you very much, this is excellent!

"Ewoud Dronkert" <fi*******@last name.net.invali d> wrote in message
news:dd******** *************** *********@4ax.c om...
Dawsons wrote:
Is it possible to echoe thew ACTUAL variable name into a document


function getvarname(&$va r)
{
$ret = '';
$tmp = $var;
$var = md5(uniqid(rand (), TRUE));

$key = array_keys($GLO BALS);
foreach ( $key as $k )
if ( $GLOBALS[$k] === $var )
{
$ret = $k;
break;
}

$var = $tmp;
return $ret;
}

$another = 'test';
$testvar = 'test';
echo getvarname($tes tvar); //echoes 'testvar'

--
E. Dronkert

Feb 20 '06 #5
Dawsons said the following on 20/02/2006 10:51:
So i sit here thinking, and wondering...

say for example i have a variable called $definition_lon don

Say for exaple that has not set value...

Is it possible to echoe thew ACTUAL variable name into a document, rather
than the variables information?


Maybe I'm missing something, but why can't you just do echo
'$definition_lo ndon'; ??

--
Oli
Feb 20 '06 #6
Dawsons wrote:
Thank you very much, this is excellent!


Only works for globals though.

--
E. Dronkert
Feb 20 '06 #7
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dawsons wrote:
say for example i have a variable called $definition_lon don

Say for exaple that has not set value...
If it has no value, that varable name does not exist. Bye-bye.
Is it possible to echoe thew ACTUAL variable name into a document, rather
than the variables information?


No, because a variable can have more than one, due to the way PHP handles
references. Suppose the following code:

<?php

$a = 42;

$b =& $a;
$c =& $a;
unset ($a);

?>

At this point, what is the name of the variable that holds "42"?? $b, $c,
both, or nobody??

For this issue, do not think that a variable is a variable. Think that a
variable is an entry in an ordered map (with internal pointers),
implemented as a hash table that can map two (or more) keys to the same
value.

Let me (try to) explain this concept in pseudo-C:

function foo()
{
int* a;
int* b;
inc* c;
a = b = c = malloc(sizeof(i nt));
*a = 42;
a = NULL;
}

This would have a similar behaviour than the PHP code I posted up there. In
PHP, variable names "point" to the value. A reference is a pointer to that
value. Storing a reference is making two entries on the variable hash
tables point to the same value. When no references to a value are found,
that memory is freed.

Variable management in PHP is quite complicated internally, with all that
duplicate-on-write stuff when making copies of complex variables. The kind
of stuff that operating systems do when you fork() a process.

I agree with Ewoud: you can transverse the $GLOBALS superglobal array to
search for your value, but if you have any references over there, you may
find lots of problems. Lots.

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.5.0, and PHP
5.1.2-1 generating this signature.
Uptime: 00:59:10 up 48 min, 1 user, load average: 0.78, 0.74, 0.74

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD+lyN3jc Q2mg3Pc8RAvKSAJ 0WnvCHl3pnSbriF UUpt2GaubcdYACf eTLZ
LN4aiZoWerYGDo+ 5lrF2Bk0=
=OrfI
-----END PGP SIGNATURE-----
Feb 21 '06 #8

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

Similar topics

8
2462
by: manish | last post by:
I have created a function, it gives more readability compared to the print_r function. As of print_r, it works both for array or single variable. I just want to add in it, the opton to view the variable name for the case of non array variables. Also I want to show the array name. Is there any way that the variable name that is passed to the function can be displayed. function formattedoutput($object) {
4
3247
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable name="Banner_error_2"> errormessage 2 for banner </xsl:variable>
7
1989
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename(); somename.show() Note that the class name "somename" is reused for the variable name.
2
1476
by: Ian Hubling | last post by:
Here's what I'm trying to do: I have a large number of pages that call a pop-up survey page. It is important to know what page the survey is referring to - so I am passing the name of the referring page through the URL. The problem I'm having is that when the data on the survey page is submitted through formmail, I can't seem to get the referring page's name sent too - I keep getting the variable name itself, not the contents of the...
2
2117
by: paladin.rithe | last post by:
I have no clue if this can be done, but I thought I'd ask anyway. I have a modular system where I store module information in a database. One of the types of modules that I have is one that, depending on the file, could have a different variable name in each file. I have named the module, and want to name it according to the name of the variable (ie, modulename Joe, var $Joe) Now, this variable needs to be loaded into a function, but...
5
14437
by: Angelos | last post by:
Hello, I need to dynamically specify the name of a variable. I just read that $varA = "Cat"; echo $$varA; OUTPUT: Cat What I try to establish is somehow add a bit of text on my dynamic variable name.
10
19756
by: CJM | last post by:
I'm trying to call a package/procedure in oracle (from an ASP page) which requires a number of parameters. I have got this working using OO40 but unfortunately the transaction rollback function doesnt seem to do much. So I'm now trying to use ADO instead (in the hope that ADO transactions will work), however I'm getting the above error. My initial searches havent turned up any suitable suggestions - there appear to be many reasons why...
40
1964
by: Summercool | last post by:
I wonder in PHP, can you have a function like print_debug($foo); and it will print out: $foo is: 3 that is, it will print out, most importantly, the variable name, as
3
4736
by: lfx | last post by:
Hi, I wonder how to get php variable name like in code? I have function like this: function printr($in){ echo "<pre>"; print_R($in); echo "</pre>"; }
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.