{ $markup = "<h1>{$this->title}</h1>"; $markup = $this->extend("onRender", $markup); return $markup; } } final class ProductExtension implements Extension { use ExtensionTrait; /** * @var int */ private $price = 5; /** * @param mixed $caller * @param string $markup * * @return string */ public function onRender($caller, $markup) { if (!stristr($markup, "Price")) { $markup .= "<p>Price: {$this->price}</p>"; } return $markup; } } $product = new Product(); $product->addExtension(ProductExtension::class); $product->render(); // <h1>New Product</h1><p>Price: 5</p>