PHP - use method chaining to extends previous method -


this question has answer here:

how can additional method(such laravel), extends previous in chaining ? example: $page->loadfooter()->withextension("script_name") withextension() additional method, affect result of loadfooter() method ?

in function return object, typically $this

class page {     public $footer;     public function loadfooter() {         $this->footer = file_get_contents("footer.html");         return $this;     }     public function withextension($script) {         $this->footer = str_replace($this->footer, "</body>", "<script src='{$script}'></script></body>");     } }  $page = new page(); $page->loadfooter()->withextension("script name"); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -