From 6df10d2b7728eb7640f0378bf8cb8565b2ec792c Mon Sep 17 00:00:00 2001 From: w3houde Date: Sat, 13 Jun 2026 02:57:39 +0200 Subject: [PATCH] Fix #36353 fresh object instance per iteration in getObjectsInCateg (#38748) The fetch loop reused a single $tmpobj declared before the loop and reset only $tmpobj->id before each fetch. Object classes whose fetch() does not clear every property left stale data from previous rows, and the shallow 'clone $tmpobj' kept nested object references (thirdparty, extrafields, ...) pointing at the last fetched row. Instantiate a fresh $tmpobj per row and append it directly so each returned entry is fully independent. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/categories/class/categorie.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 89d2dd2165f..aa102c0683f 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1050,11 +1050,11 @@ class Categorie extends CommonObject if ($onlyids) { $objs[] = $rec['fk_object']; } else { - $tmpobj->id = 0; - $tmpobj->fetch($rec['fk_object']); // The fetch will erase $tmpobj->id only if it succeed. + $tmpobj = new $classnameforobj($this->db); + $tmpobj->fetch($rec['fk_object']); // The fetch will set $tmpobj->id only if it succeed. // @phpstan-ignore-next-line if ($tmpobj->id > 0) { // Failing fetch may happen for example when a category supplier was set and third party was moved as customer only. The object supplier can't be loaded. - $objs[] = clone $tmpobj; + $objs[] = $tmpobj; } } }