【问题标题】:unexpected $end when using output buffer使用输出缓冲区时意外 $end
【发布时间】:2011-12-10 13:51:08
【问题描述】:

我在 php 中遇到了输出缓冲的奇怪问题。使用此代码,我在尝试要求第一个文件后收到意外的 $end 错误。 (在本例中为 /header.php)这是我的代码的设置方式:

class View
{

    function __construct()
    {
        ob_start();
            $this->page();
        ob_end_flush();
    }

    private function rekwire($filename)
    {           
        if(file_exists(APPPATH.$filename)) require(APPPATH.$filename);
        else if(file_exists(BASEPATH.$filename)) require(BASEPATH.$filename);
    }

    private function page()
    {
        $this->rekwire('/header.php');
        $this->rekwire('/page.php');
        $this->rekwire('/footer.php');
    }

}

这种结构在我的虚拟主机上对我有用。我最近在设置本地测试服务器 (WAMP) 时才遇到问题,这让我认为它可能是 php 或 apache 的设置。任何帮助表示赞赏!

【问题讨论】:

  • 我认为你实际上可以调用你的方法require,因为它是一个类成员,而不是一个全局函数,所以你不应该有任何冲突。

标签: php buffering


【解决方案1】:

对象构造函数无效:-

__construct()

应该是:

function __construct()
public function __construct() // public scope

【讨论】:

    【解决方案2】:

    我的 short_open_tags 的 php 配置设置未启用,并且头文件正在使用 echo 快捷方式

    对不起,如果这浪费了您的时间:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多