3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class Component { protected $data; abstract public function getHtml(); } class ConcreteComponent extends Component { // public function __construct() // { // $this->data = "<body></body>"; // } public function getHtml() { // return $this->data; return "<body></body>"; } } abstract class Decorator extends Component { } class ConcreteDecorator1 extends Decorator { public function __construct(Component $data) { $this->data = $data; } public function getHtml() { return $this->data->getHtml() . "<p> </p>"; } } class ConcreteDecorator2 extends Decorator { public function __construct(Component $data) { $this->value = 500; $this->data = $data; } public function getHtml() { return "<span>".$this->data->getHtml()."</span>"; } } $compo = new ConcreteDecorator2(new ConcreteDecorator1(new ConcreteComponent())); echo $compo->getHtml(); // echo "Client:\t\t\t"; // echo $compo->getValue();
based on a6Blm
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0beta1
<span><body></body><p> </p></span>