Eli wrote:
Hi,
I want to create a function that does some stuff, and then includes
another file in the place from where it was called. The idea is to run
the included file not in the function, but in the place of the caller in
the caller's environment (not in the function environment).
For example:
<?php
function includeIt($file) {
$name = "Debora";
trigger_error("Include START: '$file'");
include($file); // This include should run in the environment
// of the caller, from the place it was called.
trigger_error("Include END: '$file'");
}
$name = "Joe";
echo "Hello!";
includeIt("msg.inc"); // The file should be included here, not in the
// 'includeIt' function.
// Say the file 'msg.inc' uses the $name
// variable from the caller's environment.
// In this case, I want it to say hello to Joe,
// and not to Debora.
echo "Bye!";
?>
Try
$name = "Deb";
..
function includeIt($file) {
global $name;
include($file);
}
...
does that work?
The problem is to do with variable scope (see
http://www.php.net/manual/en/language.variables.scope.php).
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php