Reply to Re: Echo the actual Variable name

Your name:

Reply:


Posted by Ivαn Sαnchez Ortega on 10/23/62 11:40

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dawsons wrote:

> say for example i have a variable called $definition_london
>
> 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(int));
*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+lyN3jcQ2mg3Pc8RAvKSAJ0WnvCHl3pnSbriFUUpt2GaubcdYACfeTLZ
LN4aiZoWerYGDo+5lrF2Bk0=
=OrfI
-----END PGP SIGNATURE-----

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация