[doc-en] master: Fix Anonymous functions Example # 4 cart "add" method to support adding quantity to an existing product (#5949)

From: Date: Mon, 19 Oct 2026 08:46:49 +0000
Subject: [doc-en] master: Fix Anonymous functions Example # 4 cart "add" method to support adding quantity to an existing product (#5949)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-23858@lists.php.net to get a copy of this message
Author: Willy Bruns (willy-b) Committer: GitHub (web-flow) Pusher: jordikroon Date: 2026-10-19T10:46:46+02:00 Commit: https://github.com/php/doc-en/commit/efd61ff6a9416f6255318fd8906dbcc35d28b235 Raw diff: https://github.com/php/doc-en/commit/efd61ff6a9416f6255318fd8906dbcc35d28b235.diff Fix Anonymous functions Example # 4 cart "add" method to support adding quantity to an existing product (#5949) * Fix Anonymous functions Example # 4 cart "add" method to support adding quantity to an existing product Changed paths: M language/functions.xml Diff: diff --git a/language/functions.xml b/language/functions.xml index 5a8df8d6dc42..1148a25c65f1 100644 --- a/language/functions.xml +++ b/language/functions.xml @@ -1258,13 +1258,7 @@ class Cart public function add($product, $quantity) { - $this->products[$product] = $quantity; - } - - public function getQuantity($product) - { - return isset($this->products[$product]) ? $this->products[$product] : - FALSE; + $this->products[$product] = ($this->products[$product] ?? 0) + $quantity; } public function getTotal($tax)

« previous php.doc.cvs (#23858) next »