symfonystation to [email protected] • 2 years agoDesign Patterns in PHP 8: Builderdev.toexternal-linkmessage-square3fedilinkarrow-up12arrow-down10file-text
arrow-up12arrow-down1external-linkDesign Patterns in PHP 8: Builderdev.tosymfonystation to [email protected] • 2 years agomessage-square3fedilinkfile-text
Hi! In the realm of software development, creating complex objects often feels like trying to solve a…
minus-square@abhibeckertlink1•edit-22 years agoYou’ve missed out on the biggest feature in PHP 8. With named arguments it’s now possible for arguments to be provided in any order. You can now have functions with a large number of optional parameters, without creating a total shit show. Instead of writing this: $product = $productBuilder ->setId(101) ->setName('iPhone 13') ->setPrice(999.99) ->setDescription('New iPhone 13 with A15 Bionic chip') ->setManufacturer('Apple Inc.') ->setInventory(1000) ->setDiscount(10) ->build(); You can now do this: $product = $productBuilder->set( id: 101, name: 'iPhone 13', price: 999.99, description: 'New iPhone 13 with A15 Bionic chip', manufacturer: 'Apple Inc.', inventory: 1000, discount: 10 )->build();
You’ve missed out on the biggest feature in PHP 8. With named arguments it’s now possible for arguments to be provided in any order. You can now have functions with a large number of optional parameters, without creating a total shit show.
Instead of writing this:
You can now do this: