简体   繁体   English

PHP中的get_file_contents和作用域问题

[英]Issue with get_file_contents and scope in PHP

When I'm developing websites, I use a very (very) simple system of creating pages: 开发网站时,我使用非常(非常)简单的系统来创建页面:

//$_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;

Now, the problem is that file_get_contents doesn't return anything: not false, not a string, nada (and the file is not empty). 现在,问题在于file_get_contents不返回任何内容:不是false,不是字符串,nada(并且文件不为空)。

Execution does go inside the if and $part (which corresponds to a filename with relative path) isn't just set, but it actually points to the file . 执行确实位于if和$ part(与具有相对路径的文件名相对应)内部,而实际上指向该文件

Why is it that $_page is empty (as opposed to being set , isset($_page) actually evaluates to TRUE )? 为什么$ _page为空(相对于set ,isset($ _ page)实际上为TRUE )?

Edit: Error-reporting is on full throttle on my server, and the logs show nothing out of the ordinary. 编辑:错误报告在我的服务器上处于完全停止状态,并且日志未显示任何异常。

You are not saving the return value of file_get_contents : 您没有保存file_get_contents的返回值:

$_page . file_get_contents($part);

I think you meant to say: 我想你的意思是说:

$_page .= file_get_contents($part);

You're not doing anything with the returned value. 您对返回的值不做任何事情。 Try this: 尝试这个:

$_page .= file_get_contents($part);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM