Calling a method outside class statically, passing other method's output as parameter I have this class:

class adminTemplate {

    public static function load() 
    {
        return new self();
    }

    public function sidebarGuide()
    {
        return 'content'; // Very long html markup
    }

    public function wrapSidebars($content)
    {
        ob_start();
        echo "&lt;div class='sidebar wrapper'&gt;";
        echo $content;
        echo "&lt;/div&gt;";
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }

    // Other methods here

}


Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter:

echo adminTemplate::load()-&gt;wrapSidebars(adminTemplate::load()-&gt;sidebarGuide());


It works, but I'm pretty confident there is a more appropriate way.


Is there a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
Besides that, is there a more elegant code structure to accomplish the same "task"?
You are calling load() every time you call either sidebarGuide or wrapSidebars. Are you doing anything other than returning an instance of the class? If not, then just instantiate the class and making load() a construct would be more ideal. Doing so, your class would look like:

class adminTemplate {
    public function __construct(){}

    public function sidebarGuide(){
        return "content"; # Very long html markup
    }

    public function wrapSidebars($content){
        ob_start();
        echo "&lt;div class='sidebar wrapper'&gt;";
        echo $content;
        echo "&lt;/div&gt;";
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
}


You would then use it as follows:

$adminTemplate = new adminTemplate();
$adminTemplate-&gt;sidebarGuide();
$adminTemplate-&gt;wrapSidebars($adminTemplate-&gt;sidebarGuide());


If you wanted, you could even store the return value of sidebarGuide() in a property of the class so that you could call wrapSidebars() without injecting sidebarGuide(), as follows:

class adminTemplate {
    private $sidebarGuideReturnValue

    public function __construct(){}

    public function sidebarGuide(){
        $this-&gt;sidebarGuideReturnValue = "content"; # Very long html markup

        return $this-&gt;sidebarGuideReturnValue;
    }

    public function wrapSidebars($content = ""){
        # Make $content an optional parameter. If its not set, grab the property
        $content = ($content ? $content : $this-&gt;sidebarGuideReturnValue);

        ob_start();
        echo "&lt;div class='sidebar wrapper'&gt;";
        echo $content;
        echo "&lt;/div&gt;";
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
}


If you know that would only be calling sidebarGuide() exclusively as a param to wrapSidebars(), you could even relegate sidebarGuide()'s to a private called on instantiation in the construct, or move its body to the construct itself. 

One question that bothers me though is, is there any specific reason you want to use static load()? Or just because it looks nice?