PHP Output Block Defining and Best Practices I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive answer on the object oriented approach to large block string storage and output in PHP. Given the following example, how could I change my approach in a way that might cause Zeev Suraski to pat me on the back and say Mazel Tov (beside using HTML5)?

&lt;?php

class OutputConstructor extends ContentRetriever // Or whatever I decide to name it
{

    protected $htmlHeadBlock;

    public function __construct()
    {

        $this-&gt;setHtmlHeadBlock();

    }

    protected function setHtmlHeadBlock()
    {

        ob_start();
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;

        &lt;title&gt;&lt;?php echo $this-&gt;pageTitle; ?&gt;&lt;/title&gt;

        &lt;link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" /&gt;
        &lt;link rel="icon" href="images/favicon.ico" type="image/x-icon" /&gt;

        &lt;meta name="description" content="&lt;?php echo $this-&gt;pageDescription; ?&gt;" /&gt;
        &lt;meta name="keywords" content="&lt;?php echo $this-&gt;pageKeywords; ?&gt;" /&gt;

        &lt;link type="text/css" rel="stylesheet" href="css/style.css" /&gt;
        &lt;script type="text/javascript" src="js/functions.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
&lt;?php
        $this-&gt;htmlHeadBlock = ob_get_clean();

    }

    public function getHtmlHeadBlock()
    {

        return $this-&gt;htmlHeadBlock;

    }

} // End of OutputConstructor

?&gt;


The general theme I'm going with in this example class is that on construction, html is stored in a variable via output buffer and then returned by a public method. When evaluating this code, consider that the html will not be static. Page title, description, keywords and the such will be subbed out with dynamic property references. My overall question is: In object oriented programming, ideally where should the output be stored? PHP's DOMDocument class, however useful, doesn't really answer this question for me. Also in this instance, is there any best practice trade-off between using an output buffer and heredoc syntax? Thanks in advance for your guidance!
The first problem i can see and many other's is that your hardcoding output data, why would you hard code output data on within a language that was built for dynamic content creation.

I would suggest that you restructure your class to combine several entites into one, for example, when creating a html web page, i usually is constructed of 5 major compoinants, for isntance:


Page

Head
Body

Header
Main
Footer




Taking this into consideration i would like to make my code so it would act in the same way, create 6 or so classes called:  HTMLPage, HTMLHead, HTMLBody, HTMLBodyHeader, HTMLBodyMain, HTMLBodyFooter

Now each class should be assigned to it's parent, for example:

The Head and Body belong to the Page, and the Header,Main and Fotter belong to the Body, this taken into consideration you should look at the following structure:

/*
 * Create a Page
*/
$Page = new Page("DOCTYPE");

/*
 *Create a Head
*/
$Head = new Head();
$Head-&gt;title = "My Practical Home Page";
$Head-&gt;addScript("http://google.com/example.js");
$Head-&gt;addStyle("http://google.com/example.css");
$Head-&gt;addMeta('blah','..blah..');

/*
 * Create a Body Object
*/
$Body = new Body("charset");
$Body-&gt;layout = new HTMLLayout("some_file_to_specifiy_the_layout");
$Body-&gt;SetContent('LeftBlock.Top','Hello World');

/*
 * Create Footer
*/
$Footer = new Footer('default_footer.php');

/*
 * Add all the segments to the main page!
*/
$Page-&gt;head = $Head;
$Page-&gt;body = $Body;
$Page-&gt;body-&gt;header = $Header;
$Page-&gt;body-&gt;main = "....";
$Page-&gt;body-&gt;footer= $Footer;

/*
 * Send the page to the browser!
*/    
$Page-&gt;Display();


I will leave it down to you to figure out the classes