Hi'
I don't have much perspective on XY scripting, so you'll probably get more practical examples from others.
But at least here's the start of an answer.
Regarding your example, AFAIK:
1. eval() is a command that processes data - like
round() for example. It doesn't 'define' anything, and is not an alternative to
'set',
'global', or
'perm'. So in your example, your second line doesn't get any information from the first. At least it should be:
$a = eval("$a = 1;"); echo $a;
2. eval() is not meant to be fed literally with a 'declaration' (e.g. x=y), but (to simplify), with some form of operation (e.g. x+y,
$var1+$var2), or more importantly combination (e.g. xy,
$var1$var2).
I scanned my scripts to find where I'd used it with some practical example.
In the following case, I needed to know the path of the active pane, but based on its pane number (i.e. <xypane1> or <xypane2>), because for technical reasons it wasn't possible to ask for the 'active pane':
Code: Select all
$x = (get("pane") == 1)? 1 : 2;
// (...)
echo eval("<xypane".$x.">");
Edit: added quotes to the last line to make it more proper, but you can do without them.
In this next case, I wanted the HTML formatting of a report to be easily modifiable by variables in the header of the script. Some of them needed to be combined, e.g to obtain the left padding style from the variables (overall margins + left spacing):
Code: Select all
$Margin = 12;
$LeftColSpacing = 20;
// (...)
$myReport = $myReport."<style type='text/css'> #TD2{padding-left:".eval($Margin+$LeftColSpacing)."px;}</style>";
Last but not least, one of the interesting uses of eval() is to combine variables. I had no real example, so here's a working but useless one:
Code: Select all
$Pass1 = "foo";
$Pass2 = "bar";
$Pass3 = "done!";
while ($i < 3) {
$i++;
echo eval($Pass$i);
}
Well, I hope there's not too much BS in my examples

, and that it sheds some light on your question...
Have a nice day!
Flux