PHP - use method chaining to extends previous method -
this question has answer here:
- php method chaining? 7 answers
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
Post a Comment