I write a function named import() to import all files under a folder:
[PHP]define('DS', DIRECTORY_SEPARATOR);
define('ROOTDIR', realpath(dirname(__FILE__).DS.'..'.DS));
function import($dir)
{
$dirObj = dir($dir);
if ($dirObj->handle !== false)
{
while (false !== ($entry = $dirObj->read()))
{
if ($entry == '.' || $entry == '..')
{
continue;
}
{
$rtn = include_once($dir.DS.$entry);
print $rtn;
}
}
}
else
{
die('no such directory');
}
$dirObj->close();
}
[/PHP]
Then I put this function into gobal.php which is included in index.php
[PHP]require_once('includes/global.php');
import( ROOTDIR.'config' );
print $db_host;[/PHP]
Under the config folder I hava a file named config.php :
[PHP]$db_host = "localhost";
$db_user = "root";
$db_pwd = "123456";
$db_name = "match";[/PHP]
The problem is it doesn't print "localhost" but nothing.
If i put the code of import() function in index.php direct ,it work successfully.
why? Thank you very much .