|
Posted by Richard Davey on 06/16/05 04:42
Hello,
Wednesday, June 15, 2005, 2:33:48 PM, you wrote:
ncn> I want to write a trace procedure and call it with variable
ncn> names, and I am having trouble with the syntax. My goal is to
ncn> have a procedure that will echo lines such as:
ncn> Trace: $myvar="the contents of $myvar
ncn> My attempt that didn't work is to write a function:
ncn> function my_trace($m){
ncn> echo ("\n<br>TRACE: $m = ");
ncn> eval("\$t=\"$m\";");
ncn> echo($t."<br>\n");
ncn> }
Here's one way:
function my_trace ($varname, $varvalue)
{
$varvalue = print_r($varvalue, true);
echo "TRACE: $varname = \"$varvalue\"<br />";
}
my_trace("\$my_var", $my_var);
Another might be to look at the var_dump and var_export functions.
Best regards,
Richard Davey
--
http://www.launchcode.co.uk - PHP Development Services
"I do not fear computers. I fear the lack of them." - Isaac Asimov
Navigation:
[Reply to this message]
|