同じレベルの抽象化を維持しながら、これを適切に行う方法を誰かに教えてもらえますか?私はこれらの2つの基本的なクラスを持っていますが、それは私が望むようには機能しません。最終結果は次のようになります。
<div class="test">
content
</div>
私がこのようにすると:
class Wrapper{
protected $_html = '';
public function open(){
$this->_html .= '<div class="test">';
}
public function close(){
$this->_html .= '</div>';
}
public function __toString(){
return $this->_html;
}
}
class Content{
protected $hmtl .= '';
public function content(){
$wrapper = new Wrapper();
$wrapper->open();
$this->html .= 'test';
$wrapper->close();
}
public function __toString(){
return $this->_html;
}
}
$ content = new Content(); echo $ content-> content();
私は得ます、そしてはい、これはソースからです:
"content";
私がこのようにすると:
class Wrapper{
protected $_html = '';
public function open(){
echo $this->_html .= '<div class="test">';
}
public function close(){
echo $this->_html .= '</div>';
}
// Technically don't need this
public function __toString(){
return $this->_html;
}
}
私は得ます、そしてはい、これはソースからです、
<div class="test"></div>
"content"
だから私は何が間違っているのですか?また、同じレベルの抽象化を維持して、目的の出力を取得するにはどうすればよいですか?