Repository: glpi-project/glpi (PHP)

Issue:
Crash when trying to save a knowledge article with no category
### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Version

11.0.2

### Bug description

When I try to save a knowledge base article with no category - such that it shows up under the 'without category' section in Self-Service -, I get an unexpected error message. When looking up in the logs I get this error:

<img width="1247" height="231" alt="Image" src="https://github.com/user-attachments/assets/6894a9e5-506e-4c0a-8013-a359d42490c2" />

### Relevant log output

```shell

```

### Page URL

_No response_

### Steps To reproduce

1. Create a new knowledge article leaving the 'knowledgebase category' empty.
2. Hit Save.
3. The unexpected error pops up and the item is not saved.

### Your GLPI setup information

_No response_

### Anything else?

_No response_


Discussion: Indeed, if you leave the "Category" item empty, an error appears in the logs.
I checked with an account with maximum rights in GLPI and the article in the knowledge base has been saved and is opening. The only difference for me is that if you leave the category empty, you will get an error in the log, and if you fill it in, there will be no error.
```
[2025-11-10 15:36:25] glpi.WARNING:   *** Warning: foreach() argument must be of type array|object, string given at CommonDBTM.php line 6347
  Backtrace :
  ./src/CommonDBTM.php:6347                          
  ./src/KnowbaseItem.php:757                         CommonDBTM->update1NTableData()
  ./src/CommonDBTM.php:1812                          KnowbaseItem->post_updateItem()
  ./front/knowbaseitem.form.php:77                   CommonDBTM->update()
  ...Glpi/Controller/LegacyFileLoadController.php:64 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:197        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:70                              Symfony\Component\HttpKernel\Kernel->handle()

``` 
Actually, I need to edit the case. What I tested is editing an existing KB article having a category and removing this category. Sorry for the confusion. So, the steps to reproduce are:
 
1. Edit a KB article having a KB category.
2. Remove the category leave the field empty.
3. Hit Save.
4. The unexpected error pops up and the item is not saved with the empty category.
I confirm. This function only seems to be used for this specific case, so only this dropdown seems affected.



Fix (patch):
diff --git a/src/CommonDBTM.php b/src/CommonDBTM.php
index 3d4dd6e030d..a3dc641cfec 100644
--- a/src/CommonDBTM.php
+++ b/src/CommonDBTM.php
@@ -6331,6 +6331,10 @@ protected function update1NTableData(
         // Get input value
         $input_value = $this->input[$field] ?? null;
 
+        if ($input_value === '') {
+            $input_value = [];
+        }
+
         // See dropdownField twig macro, needed for empty values as an empty
         // array won't be sent in the HTML form
         $input_defined = (bool) ($this->input["_{$field}_defined"] ?? false);