when including a file using php function not work?

Posted by John Smiith on Pro Webmasters See other posts from Pro Webmasters or by John Smiith
Published on 2012-06-24T13:28:44Z Indexed on 2012/06/24 15:25 UTC
Read the original article Hit count: 200

Filed under:

MY PHP FUNCTION IS

function functionName()
{
include($_SERVER['DOCUMENT_ROOT']."/path/file.php");
}

Content of File.php is

$foo = 'bar';

Calling function (content of file test.php)

functionName();

When call function and variable not work

echo $foo;  <- not works

But when adding code below its works (content of file test.php)

include($_SERVER['DOCUMENT_ROOT']."/path/file.php");
echo $foo; <- its works

© Pro Webmasters or respective owner

Related posts about php