Source: sebastiandedeyne.com

Named arguments
September 15, 2022 ∙ by https://sebastiandedeyne.com/ Look at this code, I have no idea what false, false, true conveys. $page->render(false, false, true); A pattern I often see in older code is an associative array as the single parameter.

class Page { private bool $showFooter = true; private bool $showHeader = true; private bool $includeAssets = false; public function showFooter(bool $showFooter): self { $this->showFooter = $showFooter; return $this; } public function showHeader(bool $showHeader): self { $this->showHeader = $showHeader; return $this; } public function includeAssets(bool $includeAssets): self { $this->includeAssets = $includeAssets; return $this; }

Proper IDE support, type safety, no internal state required, keeps the object’s public methods to a minimum.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners