<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: How to get a variable name as a string in PHP</title>
	<atom:link href="http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/feed" rel="self" type="application/rss+xml" />
	<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php</link>
	<description>Internet Solutions</description>
	<pubDate>Fri, 10 Feb 2012 18:28:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: admin</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-655</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 03 Feb 2011 08:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-655</guid>
		<description>for comments #6 and #7

First I was excited to see how your solution works.

After some tries, I realized that "compact" is of complete no use here...

You have to enter the variable name as a string parameter... to finally get this variable name...

a simple 
function varName($theVarName) { return $theVarName; }
does the same.  :(

Problem is to enter the variable itself as a parameter to get its name.</description>
		<content:encoded><![CDATA[<p>for comments #6 and #7</p>
<p>First I was excited to see how your solution works.</p>
<p>After some tries, I realized that &#8220;compact&#8221; is of complete no use here&#8230;</p>
<p>You have to enter the variable name as a string parameter&#8230; to finally get this variable name&#8230;</p>
<p>a simple<br />
function varName($theVarName) { return $theVarName; }<br />
does the same.  <img src='http://mach13.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Problem is to enter the variable itself as a parameter to get its name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to get a variable name as a string in PHP - Making stuff work - Tech Notes</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-654</link>
		<dc:creator>How to get a variable name as a string in PHP - Making stuff work - Tech Notes</dc:creator>
		<pubDate>Thu, 03 Feb 2011 03:07:06 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-654</guid>
		<description>[...] http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php" rel="nofollow">http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EngineerGreg</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-653</link>
		<dc:creator>EngineerGreg</dc:creator>
		<pubDate>Wed, 02 Feb 2011 23:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-653</guid>
		<description>You can do it by converting the variable to a key/value set before passing it to the function.

    function varName($theVar) {  
       $variableName = key($theVar);  
       $variableValue = $theVar[$variableName];  
       echo ('The name of the variable used in the function call was '.$variableName.'');  
       echo ('The value of the variable used in the function call was '.$variableValue.'');  
    }
    $myVar = 'abc';
    varName(compact('myVar'));

Though I don't recommend creating a reference to a nameless variable, `function varName(&#38;$theVar)` works too.

Since compact() takes the variable name as a string rather than the actual variable, iterating over a list of variable names should be easy. 

As to why you would want to do this -- don't ask me but it seems like a lot of people ask the question so here's my solution.</description>
		<content:encoded><![CDATA[<p>You can do it by converting the variable to a key/value set before passing it to the function.</p>
<p>    function varName($theVar) {<br />
       $variableName = key($theVar);<br />
       $variableValue = $theVar[$variableName];<br />
       echo (&#8217;The name of the variable used in the function call was &#8216;.$variableName.&#8221;);<br />
       echo (&#8217;The value of the variable used in the function call was &#8216;.$variableValue.&#8221;);<br />
    }<br />
    $myVar = &#8216;abc&#8217;;<br />
    varName(compact(&#8217;myVar&#8217;));</p>
<p>Though I don&#8217;t recommend creating a reference to a nameless variable, `function varName(&amp;$theVar)` works too.</p>
<p>Since compact() takes the variable name as a string rather than the actual variable, iterating over a list of variable names should be easy. </p>
<p>As to why you would want to do this &#8212; don&#8217;t ask me but it seems like a lot of people ask the question so here&#8217;s my solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yehia</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-651</link>
		<dc:creator>Yehia</dc:creator>
		<pubDate>Tue, 11 Jan 2011 11:04:37 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-651</guid>
		<description>Impressive.</description>
		<content:encoded><![CDATA[<p>Impressive.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: reeze</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-650</link>
		<dc:creator>reeze</dc:creator>
		<pubDate>Fri, 05 Nov 2010 02:36:56 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-650</guid>
		<description>Thanks for sharing.
I trying to find a way  to do the samething you have done. I choose to use php extension. then I find your solution. It works great. but the other day I found It can't work like:

$a = 10;
$b =&#38;$a;

var_name($b, get_defined_vars()); // a instead of a.</description>
		<content:encoded><![CDATA[<p>Thanks for sharing.<br />
I trying to find a way  to do the samething you have done. I choose to use php extension. then I find your solution. It works great. but the other day I found It can&#8217;t work like:</p>
<p>$a = 10;<br />
$b =&amp;$a;</p>
<p>var_name($b, get_defined_vars()); // a instead of a.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: youlleck</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-648</link>
		<dc:creator>youlleck</dc:creator>
		<pubDate>Thu, 12 Aug 2010 18:23:35 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-648</guid>
		<description>Works only when there are no class objects - catchable fatal error otherwise</description>
		<content:encoded><![CDATA[<p>Works only when there are no class objects - catchable fatal error otherwise</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shafy</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-647</link>
		<dc:creator>shafy</dc:creator>
		<pubDate>Tue, 10 Aug 2010 05:39:56 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-647</guid>
		<description>Good Done!</description>
		<content:encoded><![CDATA[<p>Good Done!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cum sa extragi numele unei variabile in PHP? &#124; WorldIT</title>
		<link>http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php/comment-page-1#comment-646</link>
		<dc:creator>Cum sa extragi numele unei variabile in PHP? &#124; WorldIT</dc:creator>
		<pubDate>Sun, 18 Jul 2010 08:19:53 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=7#comment-646</guid>
		<description>[...] este faptul ca internetul nu prezinta o rezolvare a acesteia, sau e foarte greu de gasit. Totusi, cineva a abordat problema intr-un mod ingenios, care va fi prezentat mai jos. Acesta s-a folosit de o [...]</description>
		<content:encoded><![CDATA[<p>[...] este faptul ca internetul nu prezinta o rezolvare a acesteia, sau e foarte greu de gasit. Totusi, cineva a abordat problema intr-un mod ingenios, care va fi prezentat mai jos. Acesta s-a folosit de o [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- e-pla.net::website monitoring -->



