Repository navigation
Nit/trivial: Fix Anonymous functions Example # 4 cart "add" method to support adding quantity to an existing product - #5949
Open
willy-b wants to merge 1 commit into
Conversation
…ng quantity to an existing product At https://web.archive.org/web/20261014211813/https://www.php.net/manual/en/functions.anonymous.php#:~:text=add($product,%20$quantity) the add method of the shopping cart example is written: ``` public function add($product, $quantity) { $this->products[$product] = $quantity; } ``` The implementation does not match the name, and is more like "set", as if one called add twice for the same product it would not increment the quantity but replace with the value it was last called with, e.g.: ``` $my_cart->add('butter', 1); $my_cart->add('butter', 1); ``` would result in a quantity of 1 for butter instead of 2. This commit fixes that to avoid distraction from the point of the example which is the getTotal method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nit/trivial - feel free to ignore or accept, figured I'd share in case you are interested to take the update.
At https://web.archive.org/web/20261014211813/https://www.php.net/manual/en/functions.anonymous.php#:~:text=add($product,%20$quantity)
the add method of the shopping cart example was written:
The implementation does not match the name, and is more like "set",
as if one called add twice for the same product it would not increment the quantity but replace with the value it was last called with, e.g.:
would result in a quantity of 1 for butter instead of 2.
This commit fixes that to avoid distraction by a strange
addmethod from the point of the example which is thegetTotalmethod.