RE: Is there a way to get a variable name as a string?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi Daevid

FWIW, I was trying to do the exact same thing a while back, and came to
the conclusion that it wasn't possible.

Rob

> -----Original Message-----
> From: Daevid Vincent [mailto:daevid@xxxxxxxxxx] 
> Sent: Tuesday, 19 July 2005 11:28 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Is there a way to get a variable name as a string?
> 
> 
> Is there a way to get the name of a variable as a string? For 
> example...
> 
> Function myname ($foo)
> {
> 	echo "the variable name passed in is ".realname($foo);
> }
> 
> myname($bar);
>        ^^^^
> 
> I want to see printed out:
> 
> "the variable name passed in is bar"
> 					  ^^^
> 
> Dig what I'm trying to do?
> 
> And 'why?' you may ask am I trying to do this... Well, I am 
> sick of always
> putting an "echo 'printing out bar:'; print_r($bar);" all the 
> time. I want
> to make a wrapper function.
> 
> I also have written one for XML that would be nice to make a 
> NAME='bar'
> attribute...
> 
> /**
> * Print out an array in XML form (useful for debugging)
> * @access	public
> * @author 	Daevid Vincent [daevid@xxxxxxxxxx]
> * @since 	4.0b4
> * @version 	1.0
> * @date    	07/18/05
> */
> function print_r_xml($myArray)
> {
> 	print xmltag('ARRAY', array('NAME'=>'myArray'), 1);
> 	foreach($myArray as $k => $v)
> 	{
> 		if (is_array($v))
> 			print_r_xml($v);
> 		else
> 			print xmltag($k,htmlspecialchars($v));
> 	}
> 	print xmltag('ARRAY', null, 2);
> }
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux