Forum Moderators: coopster

Message Too Old, No Replies

Eval() and Extract()

         

asantos

2:00 am on Jul 17, 2006 (gmt 0)

10+ Year Member



Hi guys, i need some urgent help at something.

I have my index.php which executes some code BEFORE printing any output, and then executes some code AFTER some of the output has been already printed.

Lets suppose that:
$rs->fields['before'] = '$name = "Andres";';
$rs->fields['after'] = 'echo $name;';


<?print_before($rs->fields['before']);?>
<html>
...
<?print_after($rs->fields['after']);?>
...
</html>

This an example of the functions:
function print_before($code) {
eval($code);
}

function print_after($code) {
extract($GLOBALS, EXTR_SKIP);
eval($code);
}

The problem is that print_after is not getting the $name value that has been already seted in print_before.

Any ideas?

eelixduppy

2:10 am on Jul 17, 2006 (gmt 0)



This seems to be an issue of variable scope [php.net]. Try something like:

$rs->fields['before'] = '$GLOBALS["name"] = "Andres";';
$rs->fields['after'] = 'echo $GLOBALS["name"];';

Umm...yea..something like that. Hope this helps.