PHP中get_file_contents和scope的问题


Issue with get_file_contents and scope in PHP

当我开发网站时,我使用一个非常(非常)简单的系统来创建页面:

//$_page is, of course, declared above the loop, just as $needed_modules is.
foreach ($needed_modules as $part) 
{
    global $_page;
    if (file_exists($part)) {
        $_page . file_get_contents($part);
    } else {
        //404
    }
}
echo $_page;

现在,问题是file_get_contents不返回任何东西:不是false,不是字符串,没有(文件是而不是空)。

execute 放入if中,并且$部分(对应于带有相对路径的文件名)不仅被设置,而且它实际上指向文件

为什么$_page是空的(而不是set, isset($_page)实际上求值为TRUE)?

编辑:错误报告在我的服务器上是全速运行的,日志显示没有任何异常。

您没有保存file_get_contents的返回值:

$_page . file_get_contents($part);

我想你的意思是:

$_page .= file_get_contents($part);

您没有对返回值做任何操作。试试这个:

$_page .= file_get_contents($part);