Search code examples
phpbuffering

unexpected $end when using output buffer


I am having a strange issue with output buffering in php. with this code i get an unexpected $end error after attempting to require the first file. (in this case /header.php) here is how my code is set up:

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');
    }

}

this structure has worked for me on my webhost. I have only had the problem recently when setting up a local testing server (WAMP) which makes me think that it could be a setting with either php or apache. Any help is appreciated!


Solution

  • My php configuration setting for short_open_tags was not enabled and the header file was using the echo shortcut

    Sorry if this wasted your time :)