oop - how to change a class method behavior and output in php -


how can design pattern can affect calling methods of class , getting output them, example when use return $this can call multiple methods using pointers in approach, cant affect previous called method through last called method..

instance code :

layout1.php |--------------| <div>   {content}  </div>   index.php  |-----------|  //return output $view->layout('layout1')->content('test'); 

in case instance code changed following

//echo output $view->layout('layout1'); 

i need function informed , show different behavior on sending output. instance , in first code output value should returned in second one, value must directly echoed..

sample code :

layout1.php |--------------| <div>  {content}  </div>   index.php  |-----------|  $view = view();  //return output $view->layout('layout1')->content('test');   //echo output $view->layout('layout1');     view.php |-----------|  class view{   public function layout($file){    return $this;  }    public function content($html){   return $this;  }  } 

thank in advance help...

hi it's impossible change chain call rule. can change approach

$view->content('test')->layout('layout1'); 

as problem solved :)

or

class view{   public function layout($file){    return $this;  }    public function content($html){   return $this;  } public function __tostring(){ return $vars; // in string format } 

and

echo $view->layout('layout1'); // echo result $view->layout('layout1')->content('test'); // return result 

}


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -