0

have a file like so:

<?php
require_once "properties.php";
$GLOBALS["to_home"] = "../sfair";
echo tohome () . "index.php";
?>

And properties.php:

<?php
function tohome()
{
if(isset($GLOBALS['to_home']))
{
return $GLOBALS['to_home'] . "/";
}
else
{
return "';
}
}

Which should give me ../stair/index.php. But instead gives me index.php. How can I make the included file be able to access the variables of the including files? note: I found another answer ("unable to access global variable from included file" but it did not work.

Ethan McTague
  • 1,691
  • 2
  • 14
  • 39

1 Answers1

0

Can't you send the $GLOBALS["to_home"] with the Function call? That's what functions are for...

echo tohome($GLOBALS["to_home"]) . "index.php";

Of course you will have to change the function contents, but I guess you will get the idea.

Werner
  • 405
  • 5
  • 15
  • yes. in properties.php I would have to add a default definition for $to_home, and then instead of checking is set I would check if $to_home is equal to that default value. It worked. – Ethan McTague Jan 19 '14 at 14:29