echoはコンテンツをエコーし、returnはさらに処理するためにコンテンツを返すことを知っています。しかし、私は機能を言った:
class Content{
protected $_html = '';
public function display_content(){
$this->_html = 'content';
}
public function __toString(){
return $this->html;
}
}
それから私が以下を持っているいくつか:
$content = new Content();
<p><?php $content->disaply_content(); ?></p>
私は得る:
<p></p>
content
ページのソースコードとして。エコーするか、単に戻るかは関係ありません。どちらの方法でも、タグの外側に表示されます。
アイデア?