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; } } }